I would like to run some command (e.g. command) using perl’s system(). Suppose command is run from the shell like this:
command --arg1=arg1 --arg2=arg2 -arg3 -arg4
How do I use system() to run command with these arguments?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Best practices: avoid the shell, use automatic error handling –
IPC::System::Simple.Edit: a rant follows.
eugene y’s answer includes a link to the documentation to system. There we can see a homungous piece of code that needs to be included everytime to do
systemproperly. eugene y’s answer shows but a part of it.Whenever we are in such a situation, we bundle up the repeated code in a module. I draw parallels to proper no-frills exception handling with
Try::Tiny, howeverIPC::System::Simpleassystemdone right did not see this quick adoption from the community. It seems it needs to be repeated more often.So, use
autodie! UseIPC::System::Simple! Save yourself the tedium, be assured that you use tested code.