Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl作为批处理脚本工具-完全管道化子进程?_Perl_Shell_Batch File_Pipe - Fatal编程技术网

Perl作为批处理脚本工具-完全管道化子进程?

Perl作为批处理脚本工具-完全管道化子进程?,perl,shell,batch-file,pipe,Perl,Shell,Batch File,Pipe,如果这里的一些术语可能有误,我深表歉意。如果我对某事使用了错误的术语,请随时纠正我 是否可以将Perl用作运行“批处理”脚本的“高级shell”?(在Windows上) 我在替换使用perl脚本变得太复杂的.bat/.cmd脚本时面临的问题是,我不能像shell那样轻松地运行子进程 也就是说,我希望在perl脚本中执行与shell在调用子进程时相同的操作,即完全“连接”STDIN、STDOUT和STDERR 例如: 食蝠- @echo off echo Hello, this is a simp

如果这里的一些术语可能有误,我深表歉意。如果我对某事使用了错误的术语,请随时纠正我

是否可以将Perl用作运行“批处理”脚本的“高级shell”?(在Windows上)

我在替换使用perl脚本变得太复杂的
.bat
/
.cmd
脚本时面临的问题是,我不能像shell那样轻松地运行子进程

也就是说,我希望在perl脚本中执行与shell在调用子进程时相同的操作,即完全“连接”STDIN、STDOUT和STDERR

例如:

食蝠-

@echo off
echo Hello, this is a simple script.
set PARAM_X=really-simple

:: The next line will allow me to simply "use" the tool on the shell I have open, 
:: that is STDOUT + STDERR of the tool are displayed on my STDOUT + STDERR and if
:: I enter something on the keyboard it is sent to the tools STDIN

interactive_commandline_tool.exe %PARAM_X%

echo The tool returned %ERROLEVEL%
但是,我不知道如何在perl中完全实现这一点(有可能吗?)

foo.pl-

print "Hello, this is a not so simple script.\n";
my $param_x = get_more_complicated_parameter();

# Magic: This sub executes the process and hooks up my STDIN/OUT/ERR and 
# returns the process error code when done
my $errlvl = run_executable("interactive_commandline_tool.exe", $param_x);
print "The tool returned $errlvl\n";
如何在perl中实现这一点?我玩过,但这似乎不起作用……

也许你会觉得有用。它允许您捕获STDOUT和STDERR(但不能实时地通过管道传输它们)。命令错误级别将以
$?

的形式返回,为什么不这样做:

print "Hello, this is a not so simple script.\n";
my $param_x = get_more_complicated_parameter();

system('cmd.exe', $param_x);
my $errorlevel = $? >> 8;
print "The tool returned $errorlevel\n";

sub get_more_complicated_parameter { 42 }
我没有您的交互式程序,但执行的shell允许我输入命令,它继承了用perl定义的环境,等等


很长一段时间以来,我一直在用perl替代Windows上更复杂的shell脚本,到目前为止,我所需要的一切都是可能的。

好的ol有什么问题?新进程应该继承您的文件描述符,即使在Windows上也是如此。普通的老式
系统
确实符合我的要求。:-)