1

My command:

c:\temp\abc.exe c:\temp\abc.ini >> c:\temp\log.log 

This works fine when executed by the command prompt.

But from VB.NET, it doesn't work (the log file was created but blank, the log file should contain log processes of abc.exe, abc.exe was not executed also).

Dim p as Process = new Process() 
Dim pi as ProcessStartInfo = new ProcessStartInfo() 
pi.Arguments = "/C c:\temp\abc.exe c:\temp\abc.ini >> c:\temp\log.log " 
pi.FileName = "cmd.exe" 
p.StartInfo = pi 
p.Start()
p.WaitForExit() 

Why?

Update: While waiting for an explanation, this is my workaround.

Dim p as Process = new Process() 
Dim pi as ProcessStartInfo = new ProcessStartInfo() 
pi.Arguments = "c:\temp\abc.ini" 
pi.FileName = "c:\temp\abc.exe" 
p.StartInfo = pi 
p.Start()
Dim output as String = p.StandardOutput.ReadToEnd()
p.WaitForExit() 

WriteLog("c:\temp\log.log", output)
EagerToLearn
  • 675
  • 7
  • 24
  • I can't find a problem in the code. Seems to be correct. Did you tried to test your application as admin? – Marco Sadowski Jun 27 '18 at 05:47
  • @MarcoSadowski Thanks for the reply. Yes I have tried running as admin, btw I updated my question, please take a look at it. – EagerToLearn Jun 27 '18 at 05:51
  • What happens if you make the `FileName` "c:\temp\abc.exe" and the `Arguments` "c:\temp\abc.ini >> c:\temp\log.log"? – jmcilhinney Jun 27 '18 at 05:53
  • @jmcilhinney I tried, the exe was executed but the log file is still blank. – EagerToLearn Jun 27 '18 at 05:54
  • Try `pi.Arguments = "/C ""c:\temp\abc.exe c:\temp\abc.ini >> c:\temp\log.log"" "` – JosephC Jun 27 '18 at 12:44
  • Your *Update* seems to be the correct solution, as per [this](https://stackoverflow.com/questions/4291912/process-start-how-to-get-the-output) question and it's top answer – JayV Jun 27 '18 at 14:10

0 Answers0