开发者

CMD and Batch help vb.net

It am trying to launch this code that would normally run from a batch file

Batch file code:

    @ECHO OFF
SET BINDIR=%~dp0
CD /D "%BINDIR%"
"%ProgramFiles%\Java\jre6\bin\java.exe" -Xincgc -Xmx1G -jar craftbukkit-0.0.1-SNAPSHOT.jar
PAUSE

Vb.net Code:

If cmbserverapplication.Text = "Bukkit Server" Then
            If System.IO.File.Exists(root + "\craftbukkit-0.0.1-SNAPSHOT.jar") = True Then
                If Environment.Is64BitOperatingSystem = True Then
                    bit = "64"
                Else
                    bit = "32"
                End If
                serverpath = "craftbukkit-0.0.1-SNAPSHOT.jar"
                Dim javapath As String
                If bit = 64 Then
                    If System.IO.File.Exists("C:\Program Files (x86)\Java\jre7\bin\java.exe") = True Then
                        javapath = "path = C:\Program Files (x86)\Java\jre7\bin\java"
                    Else
                        javapath = "pat开发者_运维问答h = C:\Program Files (x86)\Java\jre6\bin\java"
                    End If
                Else
                    If System.IO.File.Exists("C:\Program Files\Java\jre7\bin\java.exe") = True Then
                        javapath = "path = C:\Program Files\Java\jre7\bin\java"
                    Else
                        javapath = "path = C:\Program Files\Java\jre6\bin\java"
                    End If
                End If
                Dim pi As New ProcessStartInfo("Cmd.exe")
                pi.Arguments = "@ECHO OFF"
                pi.Arguments = "SET BINDIR=%~dp"
                pi.Arguments = "CD /D ""%BINDIR%"""
                pi.Arguments = """" + javapath + ".exe" + """" + " -Xincgc -Xmx1G -jar craftbukkit-0.0.1-SNAPSHOT.jar"
                pi.Arguments = "Pause"

                Process.Start(pi)

                Me.Close()

            Else
                MsgBox("The server file does not exist. Please make sure that you have select the right file type and that it has not been renamed.")
            End If

        End If
    End If

When I run the code cmd.exe opens but then nothing happens


Three issues:

  1. Your java path starts with the term "path = ", confusing the command line. Remove this.

  2. A command line can only run one command. By setting pi.Arguments repeatedly, you're replacing the command each time. The only command executed is PAUSE.

  3. Your command line for CMD is completely out. It should look something like this:

    Cmd.exe /c BatchFile.bat
    

If you really want to run multiple commands, you can use && between each line.

Try this. Change the WorkingDirectory as necessary. I purposely left the space off on the SET BINDIR command to prevent an additional space appearing in the path. On other lines, I left it there for readability.

Dim pi As New ProcessStartInfo("Cmd.exe")
pi.WorkingDirectory = "C:\Location of Batch file"
pi.Arguments = "/c " & _
    "@ECHO OFF && " & _
    "SET BINDIR=%CD%&& " & _
    """" & JavaPath & """ -Xincgc -Xmx1G -jar craftbukkit-0.0.1-SNAPSHOT.jar && " & _
    "PAUSE"
Process.Start(pi)


Here is an example of launching bat files from a web page. Should have code samples of running the batch file with C#. Should be easy to convert to VB.

http://labs.ratchet.com/566/running-command-line-bat-files-from-web-page-asp-net-c/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜