windows 如何使用 Perl 打开命令提示符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3446998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:00:46  来源:igfitidea点击:

How to open a command prompt with Perl?

windowsperlcommand-prompt

提问by VolatileRig

Ok, read that again. I need to open a windows prompt WITH perl. This is because I want multiple prompts running perl scripts in parallel, but don't want to open them all by hand. So I want a script that I can call (host), tell the number of command prompts to open (clients), path to the client script to run, and even put in inputs if the clients ask. So, two major things:

好的,再读一遍。我需要用 perl 打开一个 Windows 提示。这是因为我想要并行运行 perl 脚本的多个提示,但不想手动打开它们。所以我想要一个可以调用(主机)的脚本,告诉要打开的命令提示符的数量(客户端),要运行的客户端脚本的路径,甚至在客户端询问时输入输入。所以,主要有两点:

  1. How to open a prompt with a perl script

  2. How to pass input to that prompt

  1. 如何使用 perl 脚本打开提示

  2. 如何将输入传递给该提示

Thanks! (P.S. I know that it would be a huge mistake to run a host script that calls the same host script, hopefully my boss doesn't do that :P)

谢谢!(PS 我知道运行调用相同主机脚本的主机脚本将是一个巨大的错误,希望我的老板不会这样做:P)

回答by PP.

This might not be a Perl question, so to speak, but a Windows question. I suspect what you want to do is call "start <options> <script>".

可以这么说,这可能不是 Perl 问题,而是 Windows 问题。我怀疑您想要做的是调用“start <options> <script>”。

For example:

例如:

my $cmd = "perl -w otherscript.pl";
my $result = system( "start /LOW $cmd" );

This should start the desired command in a new window and return immediately. Type start /?for other options which can change the new script's priority, hide the next window, or run in the current window.

这应该在新窗口中启动所需的命令并立即返回。键入start /?其他选项,这些选项可以更改新脚本的优先级、隐藏下一个窗口或在当前窗口中运行。

回答by Sinan ünür

This is a DOS/Windows question, not a Perl one.

这是一个 DOS/Windows 问题,而不是 Perl 问题。

Use

system("start cmd.exe /k $cmd")

See start /?and cmd /?.

start /?cmd /?