从 GNU 并行获取退出状态值
下面的 Perl 包装器并行执行命令,保存 STDOUT 和 STDERR 到 /tmp 文件:
open(A,"|parallel");
for $i ("date", "ls", "pwd", "factor 17") {
print A "$i 1> '/tmp/$i.out' 2> '/tmp/$i.err'\n";
}
close(A);
如何从各个命令获取退出状态值?
The Perl wrapper below executes commands in parallel, saving STDOUT
and STDERR to /tmp files:
open(A,"|parallel");
for $i ("date", "ls", "pwd", "factor 17") {
print A "$i 1> '/tmp/$i.out' 2> '/tmp/$i.err'\n";
}
close(A);
How do I obtain the exit status values from the individual commands?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要获取各个作业的存在状态,并行需要将信息写入某处。我不知道是不是这样。如果没有,您可以自己做。
更新:
我去安装了
并行
。它有一个名为
--joblog {file}
的选项,它会生成带有退出代码的报告。如果您希望它输出到 STDOUT,它接受-
作为文件名。请注意,
parallel
无法通过信号识别异常死亡,因此这不包含在--joblog
报告中。使用我上面发布的解决方案,丢失的 .exit 文件将表明异常死亡。 (不过,您必须首先确保它不存在。)更新:
@Ole Tange 提到我提到的
--joblog {file}
的限制上述问题已在版本 20110722 中得到解决。To get the exist status of the individual jobs,
parallel
would need to write the info somewhere. I don't know if it does or not. If it doesn't, you can do that yourself.Update:
I went and installed
parallel
.It has an option called
--joblog {file}
which produces a report with exit codes. It accepts-
for file name if you want it to output to STDOUT.Note that
parallel
doesn't recognise abnormal death by signal, so this is not included in the--joblog
report. Using the solution I posted above, a missing .exit file would indicate an abnormal death. (You must make sure it doesn't exist in the first place, though.)Update:
@Ole Tange mentions that the limitation of
--joblog {file}
I mentioned above, the lack of logging of death by signal, has been addressed in version 20110722.GNU Parallel 20110722 在
--joblog
中有退出值和信号:GNU Parallel 20110722 has exit val and signal in
--joblog
:如果您想避免使用包装器,您可以考虑:
版本 20110422 或更高版本使其更短:
如果您的行不包含 ' 那么这也应该有效:
If you want to avoid the wrapper you could consider:
Version 20110422 or later makes it even shorter:
If your lines do no contain ' then this should work too:
您可以使用 CPAN 提供的大量提供类似功能的模块,而不是并行封装。
例如:
Instead of wrapping
parallel
, you can use any of the tons of modules available from CPAN providing similar functionality.For instance: