如何在perl中将参数传递给系统命令

编程入门 行业动态 更新时间:2024-10-24 12:20:54
本文介绍了如何在perl中将参数传递给系统命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的命令:

system("start cmd.exe /k C:\\script.pl $arg1 $arg2 $arg3");

没有正确传递参数.这样做的正确方法是什么?

is not passing the arguments correctly. What is the correct way to do this?

谢谢

推荐答案

调用 system 的最佳方式是使用数组或列表:

The best way to invoke system is with an array or a list:

my @args = ("start", "cmd.exe", "/k", "C:\\script.pl", $arg1, $arg2, $arg3); system @args; system "start", "cmd.exe", "/k", "C:\\script.pl", $arg1, $arg2, $arg3;

与 system 的单个字符串相比,这节省了如何引用参数"的复杂性,因为 shell 没有机会解释它们.另一方面,如果您希望 shell 进行 I/O 重定向或管道传输,您可能不会使用这种机制.

Compared with a single string to system, this saves the complexities of 'how to quote the arguments' because the shell doesn't get a chance to interpret them. On the other hand, if you want the shell to do I/O redirection or piping, you probably won't use this mechanism.

更多推荐

如何在perl中将参数传递给系统命令

本文发布于:2023-11-23 19:41:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中将   命令   参数   如何在   系统

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!