App works in debugger, not otherwise

Help! I want to shell to cmd.exe and run a mysql command. This works fine when running in the the VS debugger, but the cmd shell either doesn't launch, or doesn't get the standardInput characters when I run my .exe outside of the debugger. The code I want to work is:

Dim myproc As System.Diagnostics.Process
myproc = New System.Diagnostics.Process()
myproc.EnableRaisingEvents = False
myproc.StartInfo.FileName = "cmd.exe"
myproc.StartInfo.RedirectStandardInput = True
myproc.StartInfo.UseShellExecute = False
myproc.Start()
myproc.StandardInput.WriteLine("mysqldump " + DataFileName + " -u root -pspa -r " + Chr(34) + SignalFileName + Chr(34))

This seems very weird. Any help is greatly appreciated.

Thanks


Answer this question

App works in debugger, not otherwise

  • bstoker

    Thanks a million--that did it! Not that it matters now, but any ideas as to why my original code would work in the debugger, but not stand-alone

    Thanks again

  • JohnTMSDN

    You make it pretty hard on yourself by redirecting the input stream just to give cmd.exe a command. Try it like this:

    myproc.StartInfo.Filename = "cmd.exe"
    myproc.StartInfo.Arguments = "/c mysqldump " + DataFileName + ....
    myproc.Start()



  • chris house

    Redirecting the input of a console process works kinda weird. The stream gets "buffered" and the console app doesn't see any input until you written at least 2048 characters or when the input stream gets closed. In theory, it could work in the debugger when you stop debugging. That closes the input stream and the console app suddenly takes off. Or the Process object gets garbage collected...


  • App works in debugger, not otherwise