Using perl's `system`

前端 未结 4 2176
逝去的感伤
逝去的感伤 2020-11-27 08:10

I would like to run some command (e.g. command) using perl\'s system(). Suppose command is run from the shell like this:



        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 09:05

    As with everything in Perl, there's more than one way to do it :)

    The best way, Pass the arguments as a list:

    system("command", "--arg1=arg1","--arg2=arg2","-arg3","-arg4");
    

    Though sometimes programs don't seem to play nice with that version (especially if they expect to be invoked from a shell). Perl will invoke the command from the shell if you do it as a single string.

    system("command --arg1=arg1 --arg2=arg2 -arg3 -arg4");
    

    But that form is slower.

提交回复
热议问题