Lo que quiero es poder abrir un comando en la CMD y que la consola no se cierre, por ejemplo:
Código
My_Process_Info.FileName = "CMD.exe" My_Process_Info.Arguments = "/k pause"
Pero la CMD se cierra.
Así que he intentado ejecutar un FOR de Batch muy largo en la CMD para ver si así no se cierra...
Código
My_Process_Info.FileName = "CMD.exe" ' Process filename My_Process_Info.Arguments = "/k For /L %a in (1,1,100000) do echo afijgifjigjfgjifjgi" ' Process arguments
y no, no se cierra (Porque el FOR tarda en finalizar, cuando acaba si que se cierra claro xD) pero ahora lo que ocurre además es que el output de la CMD no se muestra en la CMD!, es decir, el FOR no muestra nada.
EDITO: Vale, he descubierto que el output no se muestra en la CMD porque al habilitar la propiedad de redireccionar el Standard u Error output, no muestra el output en la CMD.
Así que quiero solucionar los dos problemas:
1. Que la CMD no se cierre cuando finaliza la orden, el comando.
2. Que el output se muestre en la CMD cuando habilito la propiedad RedirectStandardOutput = True y/o RedirectStandardError = True
Este es el code, es un snippet que estoy intentando hacer:
Código
Dim My_Process As New Process() Dim My_Process_Info As New ProcessStartInfo() My_Process_Info.FileName = "CMD.exe" ' Process filename My_Process_Info.Arguments = "/k For /L %a in (1,1,100000) do echo afijgifjigjfgjifjgi" ' Process arguments My_Process_Info.UseShellExecute = False ' Don't use system shell to execute the process My_Process_Info.CreateNoWindow = False ' Show the CMD Window My_Process_Info.RedirectStandardOutput = True ' Redirect (1) Output My_Process_Info.RedirectStandardError = True ' Redirect non (1) Output My_Process.EnableRaisingEvents = True My_Process.StartInfo = My_Process_Info My_Process.Start() ' Run the process My_Process.WaitForExit() ' Wait X miliseconds to kill the process Dim Process_StandardOutput = My_Process.StandardOutput.ReadToEnd() ' Stores the Standard Output (If any) Dim Process_ErrorOutput = My_Process.StandardOutput.ReadToEnd() ' Stores the Error Output (If any) Dim Process_StartTime As String = My_Process.StartTime ' Stores the time when the process was launched Dim Process_EndTime As String = My_Process.ExitTime ' Stores the time when the process was finished Dim ERRORLEVEL = My_Process.ExitCode ' Stores the ExitCode of the process Dim result = Process_StartTime & vbNewLine & Process_EndTime & vbNewLine & ERRORLEVEL MsgBox(result) MsgBox(Process_StandardOutput) MsgBox(Process_ErrorOutput)