I have tried this command but is not working, can someone tell me why?

        Dim myProcess As Process = New Process()

        myProcess.StartInfo.FileName = "cmd.exe"
        myProcess.StartInfo.Arguments = "/C " & "rabcasm.exe " & "\Source\" & "3.3.0-1\3.3.0-1.main.asasm"

        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        myProcess.StartInfo.CreateNoWindow = True
        myProcess.Start()

        myProcess.WaitForExit(1000)
        If Not myProcess.HasExited Then
            myProcess.Kill()
        End If
        myProcess.Close()

I'd start by changing the code (for now) as follows

    Dim myProcess As Process = New Process()

    myProcess.StartInfo.FileName = "cmd.exe"
    myProcess.StartInfo.Arguments = "/K " & "rabcasm.exe " & "\Source\" & "3.3.0-1\3.3.0-1.main.asasm"

    myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
    myProcess.StartInfo.CreateNoWindow = False
    myProcess.Start()

    myProcess.WaitForExit(60000)
    If Not myProcess.HasExited Then
        myProcess.Kill()
    End If
    myProcess.Close()

Note the changes as follows

  • using /K instead of /C to keep the window open
  • using ProcessWindowStyle.Normal and CreateNoWindow = False
  • WaitForExit(60000)

Those changes will allow you to see what is happening. It is possible your process is getting hung up somewhere. Making the window visible and keeping it open will give you a chance to see if that is the case. Your WaitForProcess was only set to one second which means you were likely killing the process before it completed.

Edited 4 Years Ago by Reverend Jim

Comments
You are the best XD

What if I need to run multiple commands?
What would you recommend me?

I would make the above code into a function and pass it

exefile - the program to run
args    - the arguments
timeout - how long to wait for completion

and it could return true (if it ran to completion) or false (if it timed out and was killed). There are also ways in which you can redirect stdin, stdout and stderr so that you can get feedback (capture output and errors). You might get some ideas from the code I posted here.

This question has already been answered. Start a new discussion instead.