| [reply] [d/l] |
It's actually that I want to call the program, which will run and then create a file that I will process. Everything is done on Linux OS. So you think <system> is OK to go, right?
| [reply] |
| [reply] [d/l] |
The answer to this will depend on how your Perl script needs to interact with the external program.
Here's a non-exhaustive list of possibilities:
-
You want to wait for the program to finish and check its exit status: system may be best.
-
You want the output from the program: qx{...} (or `...`) may be the best choice — see perlop: Quote-Like Operators for details.
-
You want control over how (one of) input or output is written to or read from the program: perhaps choose open with a mode of '|-' or '-|' — see perlipc: Using open() for IPC for more details.
-
See perlipc for more complex scenarios, such as bidirectional and client/server communication.
-
There are also many modules that may do exactly what you want, e.g. the built-in IPC::* modules.
If you provide a clearer picture of your requirements, we can provide a better answer.
| [reply] [d/l] [select] |
Another useful option is the module Capture::Tiny, which combines with system to return the external programme’s exit status while also capturing its output to STDOUT and to STDERR. For example:
use Capture::Tiny 'capture';
...
my ($stdout, $stderr, $exit) = capture
{
system($cmd, @args);
};
Hope that helps,
| [reply] [d/l] [select] |
| [reply] |