简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM