0 Replies - 2987 Views - Last Post: 22 January 2012 - 09:28 AM Rate Topic: -----

#1 blasterweb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 22-December 11

Run batch file

Posted 22 January 2012 - 09:28 AM


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:
"%ProgramFiles%\Java\jre7\bin\java.exe" -Xincgc -Xmx1G -jar CraftBukkit.jar

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:

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
        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
        If Not process.HasExited Then
        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

Is This A Good Question/Topic? 0
  • +

Page 1 of 1