The Command Prompt has been a natively command-line interpreter for Windows operating systems for many years. It is still a powerful tool that is being used heavily to this day. The DOS Command action in Foxtrot executes commands written by the user as if it was the CMD executing them. You can create the action via the Action List under Advanced.
Basic commands
The DOS Command action works the same way as if you opened the Command Prompt manually on the machine. But, the powerful thing is that it supports the use of Foxtrot tokens in the command. In this first example, we use the simply command to create a folder on the desktop. The output to the selected variable will be the as the text shown in the Command Prompt after executing the command, so, you can use the output to check for any errors of the results of any given command.
IMPORTANT: If you write an invalid command or the command fails, the DOS Command action will not error the same way it will if, for example, the target is not found. Therefore, if is important to evaluate the value stored in the selected output variable if you want to be sure that the command worked as expected.
To give an example of what would happen if you run this DOS Command action, here is the output of such command.
Here is an example with an actual output of the command that you can then parse afterwards using Foxtrot formulas or the Regular Expression action.
Multiple commands
The DOS Command action does support executing multiple commands in one action.
Syntax |
Description |
Equivalent to |
---|---|---|
command1 & command2 | Execute command2 after execution of command1 has finished | command1 command2 |
command1 && command2 | Execute command2 only if execution of command1 has finished successfully | command1 IF NOT ERRORLEVEL 1 command2 |
command1 || command2 | Execute command2 only if execution of command1 has finished unsuccessfully | command1 IF ERRORLEVEL 1 command2 |
This is especially important if you need to perform a command using something in a specific folder. For example, as explained in this article about extracting data from PDF files, you can begin with a "cd" command to navigate to a specific folder and then use any given command that depends on first navigating to that folder. This is the command used in above referenced article to convert a specific .pdf file to .txt.
cd C:\ && PTCMD "[*DOWNLOADS_DIRECTORY]example.pdf"
So in this above command, it first navigates to the root C: drive folder because that is where we have the .exe file that we are using in the command, and then we execute the actual command from there.
The DOS Command action is also interesting for starting projects on other machines using the methods explained in this article as you can execute the commands directly through this action instead of creating a batch file.
Comments
0 comments
Please sign in to leave a comment.