如何获取系统进程的退出码?
假设我想从 Haskell 中执行命令 unrar x archivename
。
最好的方法是什么以及如何获取命令的退出代码?如果命令成功退出,我想删除存档,否则不删除。
Say I want to execute the command unrar x archivename
from within Haskell.
What is the best way to do it and how do I get the exit code of the command? If the command exited successfully I want to delete the archive else not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
process
库中,您将找到函数 < a href="http://hackage.haskell.org/packages/archive/process/1.0.1.5/doc/html/System-Process.html#v%3areadProcessWithExitCode" rel="nofollow">readProcessWithExitCode
,它可以满足您的需求。类似的:还有许多其他解决方案,例如
system
命令。随你挑选。In the
process
library you will find the functionreadProcessWithExitCode
, which does what you want. Something like:There are also many other solutions, such as the
system
command. Take your pick.readProcessWithExitCode
System.Process 中的 函数应该可以完成这项工作。The
readProcessWithExitCode
function fromSystem.Process
should do the job.