DEV Community

hiclab
hiclab

Posted on

How to run a Shell command in RCPTT

There are several reasons to run an external process when writing automated test cases. Those are some examples:

  • Unzip files
  • Run a script or batch file
  • Access to the processes that are running on the system
  • Create folders and files

Basically, to execute a system command, we use exec-process ECL command provided by RCPTT and pass the required parameters. Once executed, the command provides the following information:

  • Exit code
  • Stdout
  • Stderr

The executed command depends on the operating system we are using. In our case, it is Windows so we have to pass the command as argument to cmd.exe shell.

Create a new folder

exec-process cmd "/c" md "C:\\temp\\new_folder" -ignoreExitCode –ignoreStderr

The parameters ignoreExitCode and ignoreStderr are added in this case to ignore any failure if for example, there is already a folder with the same name.

Unzip files

let [val unzipCmd [concat "\"C:\\Program Files\\7-Zip\\7z\"" " x " "C:\\temp\\output.zip" " -aoa -oC:\\temp\\new_folder"]] {
    exec-process cmd "/c" $unzipCmd
} 

Windows processes

// check if a given windows process is running
proc processExists [val name] {
    exec-process cmd "/c" tasklist "/FI" [concat "IMAGENAME eq " $name] | get stdout | invoke contains $name
}
processExists "rcptt.exe" | verify-true

Oldest comments (0)