DOSCMD        Execute an internal MS-DOS command

<< Click to Display Table of Contents >>

Navigation:  Robo-FTP User's Guide > Script Programming > Script Commands > All Script Commands >

DOSCMD        Execute an internal MS-DOS command

Syntax:

DOSCMD

[ cmd ]

Arguments:

[ cmd ]

Variable or string defining an MS-DOS command such as dir, copy, mkdir, etc. to be executed.

Options:

/timeout=x

Specifies the number of seconds to wait for the command to complete. When no timeout is specified Robo-FTP will wait indefinitely. A %datetime value can also be given as an argument instead of a number of seconds.

 

/redirectio[=x]

Redirects standard output and standard error stream to the script log and also puts the content of those streams into variables %exec_stdout and %exec_stderr, respectively. Permitted values for x are true and false. The default value is true.

 

 

This script command opens a DOS command console window and executes the command specified by the [ cmd ] argument. Unlike the EXEC script command, you can use DOSCMD to run MS-DOS internal commands. Robo-FTP script execution is suspended while the command is console is running. The command console window closes automatically when the command specified by the [ cmd ] argument is finished running.

 

Important

The Windows command console does not support UNC paths as the current local working directory. If DOSCMD is executed while the Robo-FTP working directory is a UNC path the console will default to the Windows installation directory. Use the WORKINGDIR command to choose a different working folder before executing DOSCMD. Scripts that must call DOSCMD with a network folder should map a drive (see Working with Network Drives) with EXEC and net use.

 

The /timeout option allows you to specify the maximum amount of time to wait for the command console window to close. This option is useful for protecting your command script from unreliable external commands. If you do not specify a timeout and the command hangs waiting for user input (ie: Abort, Retry, Fail?) then Robo-FTP will also wait indefinitely. If the launched DOS command console window does not complete execution prior to the end of the timeout period then Robo-FTP will close the DOS command console and continue processing its script with the next line. A timeout does not necessarily close external programs launched by the DOS command console.

 

Consider the following example that runs a batch file:

 

DOSCMD "DoSomething.bat"

 

Consider the following example that lists the contents of the current folder to a file:

 

DOSCMD "dir *.* > tempfile"

 

Consider the following example where a new folder is created and the contents of the current folder is copied there:

 

DOSCMD "mkdir \newfolder"

DOSCMD "copy *.* \newfolder"

 

Consider the following example where single quote characters are used to delimit the string constant passed to the [ cmd ] argument so that the double-quote characters may be passed to the command console:

 

DOSCMD 'mkdir "new folder"'

 

Upon return, any exit code from the process launched with DOSCMD is saved in the %lasterror script variable and can be tested with any of the IFERROR commands. For example:

 

DOSCMD "fc file1.txt file2.txt"

;; "fc" returns 2 if it cannot compare the specified files

IFERROR= 2 GOTO fc_error

 

Always use the EXEC command to launch an external Windows application. If you launch such a program using DOSCMD instead, a DOS command shell is first opened, which in turns opens that external program. The external program will detach from the DOS command shell, by which point Robo-FTP can only affect the shell itself and not the external program. In particular, this will prevent the /timeout option from working as one would expect. After the timeout has expired, the shell will close, but not the external application.

 

Related command(s): EXEC, CALL, CHAIN

See also: Script File Result Codes, Working with Network Drives