Running programs

Table of contents


Description

The action is used to run third-party programs. You can run both ordinary desktop programs (Notepad, WinRar, Paint) and console utilities (ffmpeg, ImageMagick). It is possible to transfer launch parameters.


How to add an action to a project?

Through the context menu Add actionCustom codeRun the program

Or use smart search .


Where can it be applied?

  • Most often used to run console utilities. For example:

    • ImageMagick is a set of programs (console utilities) for reading and editing files of many graphic formats.

    • FFmpeg is a collection of free open source libraries that allow you to record, convert and pass digital audio and video recordings in various formats

    • running scripts in Python and other programming languages.

  • Running any other applications


How to work with an action?

Executable file

The full path to the file to be run (by clicking on the "Select files" button (highlighted in a red square) a standard file search dialog will open on the computer)

  • If the specified file is not found, then the action will end with an error

  • Variable macros can be used

  • If the directory of the executable program is in the PATH environment variable , then you can specify not the full path to the file, but only its name ( notepad.exe or calc.exe)

Startup settings

These are additional commands that are passed to the program being run. Each program has its own run parameters (you can use variable macros).

For example, running a new Chrome browser window with the URL https://zennolab.com would look like this:

When running console utilities, arguments are passed on this line.

Running timeout

It is convenient to use when you know how long the program will run. If the called program does not exit after the specified number of seconds, then the action will terminate with an error.

You can specify a fractional value.

This behavior can be disabled, described below.

Do not show program window

When this option is enabled, the running program will not be displayed.

Do not wait for the process to finish

When this setting is enabled, the execution timeout will be ignored and the action will not wait for the program to finish.

Write down EXIT CODE

The return code with which the called program ended.
Typically, programs return 0 (zero) on normal shutdown. If something else is returned, the program may have terminated with an error. To understand what this or that code means, you should type in the search query program_name exit code return_code , for example - ffmpeg exit code 137

Write STD OUT

This is the standard output stream. In other words, everything that the program writes to the console window (unless it is an error message (s)) is STD OUT

Example:

When installing ImageMagick, the program adds the path to its folder to the PATH environment variable and there is no need to write the full path to the executable file, you can write magick <here_arguments> . To demonstrate STD OUT, run the program with the -usage argument (in response, the program will write basic information about itself) and redirect STD OUT to a variable.

Write STD ERR

Will contain data if the program reports any error.

Example:

We will repeat the command from the previous paragraph, but make a mistake in the command and write -usage22

The screenshot shows that an error text got into STD ERR, saying that an incorrect argument was passed or there were not enough of them. At the same time, data also got into STD OUT - the program tells us how to use it correctly.

You can repeat the commands above. To do this, you need to install ImageMagick, then open a console window ( Win + R → enter cmd.exe → press Enter ) and enter the commands magick-usage and magick-usage22


Usage example

Let's look at some examples based on ImageMagick.

Goal: create a 600 x 600 px image, with a light blue background, labeled “ZennoPoster” (in blue), font - Arial, font size - 72. Save the result to a file along the path C:\Users\user\Desktop\result.gif next to the template. The command will look like this (convert is one of the utilities included in ImageMagick. On your computer, the path to the executable file and the desktop may differ):

C:\Program Files\ImageMagick-7.0.10-Q16\convert.exe -size 600x600 -background lightblue -gravity Center -fill blue -font Arial -pointsize 72 label:ZennoPoster C:\Users\user\Desktop\result.gif

Use your favorite search system for details on a given argument. This is outside the scope of this help.

Example # 1. ImageMagick All parameters are hardcoded

Unfortunately, all run parameters did not fit on the screenshot

After executing this action, the result.gif file will appear on the desktop

Example # 2. ImageMagick Parameters are passed as variables

  • In this example, the path to the folder with the executable file has been moved to a variable (for example, the template can run on different computers and each can have its own path).

  • All parameters were also moved to a variable (it was not necessary to save everything in one variable. You can create your own variable for each argument and list these variables in the Run parameters field)

  • The resulting file result.gif is saved in the same directory as the project file. ( {-Project.Directory-} - a system variable that stores the full path to the current project directory)

Example # 3. Running Python script

Sometimes, when searching on the Internet for solutions to a particular problem, you can find scripts written in different programming languages that do exactly what you need. You can, of course, completely rewrite the script code in C# and run it using the Custom C# code action. Alternatively, run the script using the Run Programs action and use the result of its work. The last option will be considered, based on the Python programming language.

There is a script along the path C:\ZP\my_sript.py , accepts two numbers at the input and multiplies them by each other, the response is returned to the console (in your case, the script can generate an image, text; or it can be a neural network that recognize the captcha; in general, whatever).

  • Specify C:\Users\user\AppData\Local\Programs\Python\Python38-32\python.exe as the executable file (the path may differ on your computer).

  • In the un parameters, the first thing is the path to the script ( C:\ZP\my_sript.py ), then two arguments ( 12 11).

  • After starting this action, the result will be written to the result variable - 132.

This is how it looks like running the same script in cmd.exe