ここでは専門用語の一部がオフの場合は謝罪します。私が何かに間違った言葉を使うと、私を修正してください。バッチスクリプトツールとしてのPerl - 完全に子プロセスをパイプしていますか?
「バッチ」スクリプトを実行するための「高度なシェル」としてPerlを使用できますか?
.bat
/.cmd
スクリプトが複雑すぎるperlスクリプトを置き換えるときに直面する問題は、シェルが実行するサブプロセスを簡単に実行できないことです。
つまり、子プロセスを呼び出すとき、つまりSTDIN、STDOUT、およびSTDERRを完全に「接続」するシェルと同じことを、私のperlスクリプトから実行したいと思います。
例:
foo.bat -
@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で達成できますか?私はIPC::Open3で遊んだが、これはトリックをしないようだ...
good ol' ['system'](http://search.cpan.org/perldoc?perlfunc#system)の何が問題なのですか?新しいプロセスは、Windows上でもファイル記述子を継承する必要があります。 – mob