在CLR中运行Dos命令 [英] Run Dos Command in CLR
问题描述
您好,
有人可以帮我吗?我试图运行DOS commad作为dir,但我需要使用另一种方式而不是 - > system(dir)
另外,我想捕获运行任何工具或命令时出现的错误消息(但不是标准命令如dir),例如,我有gzip当我为一个崩溃的文件运行它时,它在控制台上给我一条消息,说明错误是什么,我怎么能发现这个错误?
谢谢
Ossama F.
Hi there,
Can someone help me with this? I am trying to run a DOS commad as dir but I need it to be done using another way rather than --> system("dir")
Also, I want to catch the error message that come out from running any tool or command ( but not the standard commands as dir) , for example , I have the gzip and when I run it for a crashed file it gives me on the console a message stating what is the error , how can I catch this error ?
Thanks
Ossama F.
推荐答案
你好,
可以有人帮我这个?我试图运行DOS commad作为dir,但我需要使用另一种方式而不是 - > system(dir)
另外,我想捕获运行任何工具或命令时出现的错误消息(但不是标准命令如dir),例如,我有gzip当我为一个崩溃的文件运行它时,它在控制台上给我一条消息,说明错误是什么,我怎么能发现这个错误?
谢谢
Ossama F.
Hi there,
Can someone help me with this? I am trying to run a DOS commad as dir but I need it to be done using another way rather than --> system("dir")
Also, I want to catch the error message that come out from running any tool or command ( but not the standard commands as dir) , for example , I have the gzip and when I run it for a crashed file it gives me on the console a message stating what is the error , how can I catch this error ?
Thanks
Ossama F.
我不确定,但我认为这在.NET论坛中更好。但是,为什么你需要系统以外的东西(dir),以便你可以从执行中获取输出?
如果是这样,那么fork()会浮现在脑海中。但它已经有一段时间了。您必须关闭stdout和stderr文件句柄(而不是FILE描述符)打开2个管道,然后在这两个管道上使用dup()来替换关闭的stdout和stderr句柄。然后,FILE描述符将被重定向到管道,这些管道可以由子进程和父进程访问,因为子进程可以访问这些句柄。
请参阅:
- pipe
- 分叉
- dup
快速提问:您要为此编写什么操作系统?
Quick question: what OS are you trying to code this for?
快速提问:您要为此编写什么操作系统?
Quick question: what OS are you trying to code this for?
无所谓,Windoze符合POSIX标准。 :)
Adrian
Shouldn''t matter, Windoze is POSIX compliant. :)
Adrian
这篇关于在CLR中运行Dos命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!