Perl: calling a Perl script from another

I have a perl script that calls another script. I call it using backticks and passing an argument to this script, and it works fine.

`CQPerl call_script.pl $agr1 $agr2 $arg3`; 

But please suggest if there is another better way to do this. How can I check if the script error was due to the script being called or the script that was being called. How to execute this check from the most calling script?

+6
source share
2 answers

If you don't do error checking, backlinks may be the wrong approach. You probably want to use the system function. For more information about error handling, see the documentation.

Perl has a number of features for executing other scripts / commands:

  • backticks / qx{} If you want to read all the output right after the program ends
  • exec If you do not continue your process as another program, you will never return if succesfull
  • system If you are only interested in the success or failure of a team
  • open If you want to pass information to or from a command
  • do and require Run another Perl script here. Like C #include
  • There are modules for a three-way open so that you have access to the STDIN , STDOUT and STDERR your program. For more information, see the relevant perlipc sections.

And always use the multi-parameter forms of these calls to avoid shell escaping (can be annoying and very unsafe).

+18
source

Check the value of the perl $? special variable $? to determine if there was an error.

+4
source

Source: https://habr.com/ru/post/923335/


All Articles