[英]C# process with an input and output file
When creating a new process you can give some StartInfo with it before you start the process. 创建新流程时,可以在启动流程之前为其提供一些StartInfo。 But how would one give the input of/output to parameter. 但是如何将输入/输出提供给参数。 the output to is achievable through a File.WriteAllLines() with the output of the command. 通过File.WriteAllLines()和命令的输出可以实现to的输出。
But now the following must me achieved: 但是现在我必须实现以下目标:
C:\Windows\System32\inetsrv\appcmd.exe add site /in < iisSite.xml
But when we give the 但是当我们给
add site /in < iisSite.xml
with the arguments method of StartInfo appcmd thinks it is a parameter for it's program. StartInfo appcmd的arguments方法认为它是程序的参数。 See this error 看到这个错误
Failed to process input: The parameter
'd:\import\iisSite.xml' must begin with a / or - (HRESULT=80070057).
So we need somehow the same parsing as the command prompt would do it. 因此,我们需要某种与命令提示符相同的解析方法。
What could be possible is something like ReadAllLines and use that as an input, but I thought maybe there is a better solution. 可能是类似ReadAllLines的东西,并将其用作输入,但是我认为也许有更好的解决方案。 Any suggestions? 有什么建议么?
Thanks in advance! 提前致谢!
Stream redirection like that is a feature of the command processor cmd
. 像这样的流重定向是命令处理器cmd
。 If you want to do that then you need to invoke it and send your arguments. 如果要这样做,则需要调用它并发送参数。 See EDIT2 and EDIT3 in this post . 请参阅本文中的EDIT2和EDIT3 。
EDIT 编辑
using < is not the way to do it. 使用<不能做到这一点。 Use > 使用>
so for example: appcmd.exe add site /in > iisSiteExport.xml
因此,例如: appcmd.exe add site /in > iisSiteExport.xml
and have your program spit out all the output as if it was printing to the Console
并让您的程序吐出所有输出,就像正在打印到Console
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.