开发者

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. 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.

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 开发者_Go百科StartInfo appcmd thinks it is a parameter for it's program. 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. Any suggestions?

Thanks in advance!


Stream redirection like that is a feature of the command processor cmd. If you want to do that then you need to invoke it and send your arguments. See EDIT2 and EDIT3 in this post.

EDIT

And direct from Raymond


using < is not the way to do it. Use >

so for example: appcmd.exe add site /in > iisSiteExport.xml

and have your program spit out all the output as if it was printing to the Console

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜