1

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!

2 Answers2

1

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

Community
  • 1
  • 1
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
0

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

soniiic
  • 2,664
  • 2
  • 26
  • 40
  • No the output is not the hard part. It is about giving an xml as a parameter but the > and < are being handled as a parameter of appcmd. instead of being an own command which command prompt can handle. Why would one do an add site and export that, there is no information. Information has to go into that command – Poiu Ytrewq Aug 24 '11 at 16:26