Perl: Calling a perl script from another

后端 未结 2 1089
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 21:09

I have a perl script which calls another script. I am calling it using backticks and passing argument to that script and it works fine.

`CQPerl call_script.p         


        
相关标签:
2条回答
  • If you wan't to do error checking, backticks may be a wrong approach. You probably want to use the system function. See the documentation for all the details of error handling, examples included.

    Perl has a number of possibilites to execute other scripts / commands:

    • backticks / qx{} When you want to read all the output at once after the program has terminated
    • exec When you wan't to continue your process as another program — never returns if succesfull
    • system When you are only interested in the success or failure of the command
    • open When you want to pipe information to or from the command
    • do and require Execute another Perl script here. Similar to C's #include
    • There are modules to do a three-way open so that you have access to STDIN, STDOUT and STDERR of the program you executed. See the apropriate parts of perlipc for advanced information.

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

    0 讨论(0)
  • 2021-01-04 21:52

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

    0 讨论(0)
提交回复
热议问题