I have been working on how to redirect output from a command prompt to a textbox in real time, but I couldn't get it to work, so I tried to find a way on how to run a .bar file with contents inside it.
I tried:
- Shell
- Process.Start
but they give me an error saying, that the specified path can not be found. Here is the content of the .bat file:
@ECHO OFF SET BINDIR=%~dp0 CD /D "%BINDIR%" "%ProgramFiles%\Java\jre7\bin\java.exe" -Xincgc -Xmx1G -jar CraftBukkit.jar PAUSE
As you see, it uses Java, and when I run the .bat file using Windows Explorer, it's working as intended and the file path can be found. (the .jar file is in the same folder as the .bat file)
This is what I use to start the .bat file:
Process.Start(Application.StartupPath & "\Start.bat")
I even tried to run a regular command prompt just by:
Process.Start("cmd.exe")
and then I dragged the .bat file from explorer to the command prompt, and pressed enter, but it said the specified path could not be found.
I tried it afterwards on the in built cmd on windows (I searched cmd on the search bar and ran it) and repeated the process, but this time it worked.
Can someone help me figuring this out? Thanks
And if someone can help me with redirecting console output in real-time, then I would be appreciate it too. Here is my code for redirecting console output:
Dim filepath As String = (Path.GetFullPath(Application.StartupPath & "\Start.bat"))
Dim process As New Process()
process.StartInfo.WorkingDirectory = Application.StartupPath
process.StartInfo.FileName = "cmd.exe"
process.StartInfo.UseShellExecute = False
process.StartInfo.CreateNoWindow = False
process.StartInfo.RedirectStandardInput = True
process.StartInfo.RedirectStandardError = True
process.StartInfo.RedirectStandardOutput = True
process.Start()
Dim sIn As StreamWriter = process.StandardInput
sin.AutoFlush = True
Dim sOut As StreamReader = process.StandardOutput
Dim sErr As StreamReader = process.StandardError
Control.CheckForIllegalCrossThreadCalls = False
ConsoleOutput.Text = sOut.ReadToEnd
process.WaitForExit()
If Not process.HasExited Then
process.Kill()
sIn.Close()
sOut.Close()
sErr.Close()
End If
This only redirects the text when I close the command promopt.
But I need to figure out first how to run the .bat file and then I will find out how to redirect output
Thanks for your help

New Topic/Question
Reply



MultiQuote


|