Why this command wont execute the path properly?
The path have spaces, but with the path inside quotes, it was suposed to work.
Why it's not reading the fully path?

Path:
'C:\Users\Administrador\documents\visual' is not recognized as an internal or external command

        Dim myProcess As Process = New Process()
        myProcess.StartInfo.FileName = "cmd.exe"
        myProcess.StartInfo.Arguments = "/K echo " & Chr(34) & currPath & "\RABCDAsm\rabcasm.exe" & Chr(34)
        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()

Recommended Answers

All 14 Replies

When I echo the line for test it comes with the double quotes, but its not reading the fully path anyways.

After line 3 add the following

MsgBox(myProcess.StartInfo.Arguments)

and post the results here

Figured out I guess, I have used """" on beggining and """" on end path, and worked :D

But when I add the argument it bugs again

        Dim myProcess As Process = New Process()
        myProcess.StartInfo.FileName = "cmd.exe"
        myProcess.StartInfo.Arguments = "/K " & """" & currPath & "\RABCDAsm\rabcasm.exe" & """" & " " & """" & currPath & "\Source\3.3.0-1\3.3.0-1.main.asasm" & """"
        MsgBox(myProcess.StartInfo.Arguments)
        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()

Post the string again so I can see the new value. It might be easier to just do

Debug.WriteLine myProcess.StartInfo.Arguments

then copy and paste the text

/K "C:\Users\Administrador\documents\visual studio 2012\Projects\SWF Builder\SWF Builder\bin\Debug\RABCDAsm\rabcasm.exe" "C:\Users\Administrador\documents\visual studio 2012\Projects\SWF Builder\SWF Builder\bin\Debug\Source\3.3.0-1\3.3.0-1.main.asasm"

        Dim cLine1, cLine2 As String

        cLine1 = """" & currPath & "\RABCDAsm\rabcasm.exe"""
        cLine2 = """" & currPath & "\Source\3.3.0-1\3.3.0-1.main.asasm"""

        Dim myProcess As Process = New Process()
        myProcess.StartInfo.FileName = "cmd.exe"
        myProcess.StartInfo.Arguments = "/K " & cLine1 & " " & cLine2
        Debug.WriteLine(myProcess.StartInfo.Arguments)
        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()

Now try opening a cmd shell and pasting

cmd /K "C:\Users\Administrador\documents\visual studio 2012\Projects\SWF Builder\SWF Builder\bin\Debug\RABCDAsm\rabcasm.exe" "C:\Users\Administrador\documents\visual studio 2012\Projects\SWF Builder\SWF Builder\bin\Debug\Source\3.3.0-1\3.3.0-1.main.asasm"

When I write only "C:\Users\Administrador\documents\visual studio 2012\Projects\SWF Builder\SWF Builder\bin\Debug\RABCDAsm\rabcasm.exe" "C:\Users\Administrador\documents\visual studio 2012\Projects\SWF Builder\SWF Builder\bin\Debug\Source\3.3.0-1\3.3.0-1.main.asasm"

it works.
Without "cmd /K "

I dont know what do to anymore

I think what is happening is the blanks in the path are screwing things up. There are two things you could try. One is to use the 8.3 version of the path. You can get this by doing "dir /x". The other possibility is to add another set of double quotes around both arguments. You should be able to verify this by trying

cmd /K ""C:\Users\Administrador\documents\visual studio 2012\Projects\SWF Builder\SWF Builder\bin\Debug\RABCDAsm\rabcasm.exe"" ""C:\Users\Administrador\documents\visual studio 2012\Projects\SWF Builder\SWF Builder\bin\Debug\Source\3.3.0-1\3.3.0-1.main.asasm""

How can I type commands sequentially in the same window?
Like multiple commands handling, one command by line, like using WriteLine, but in the same cmd window.

The following code implements a GUI front end for a command shell. As it stands, you type the command into the textbox at the bottom then click "Execute". You can bypass this and just feed commands to the shell directly as in

Submit("dir d:\temp")

If you clear txtStdOut and txtStdErr at the top of the Submit sub then you can scan either or both for results and errors after the command has executed.

'                                                                           '
'  Name:                                                                    '
'                                                                           '
'    CommandShell.vb                                                        '
'                                                                           '
'  Description:                                                             '
'                                                                           '
'    GUI front end for a command line shell                                 '
'                                                                           '
'  Notes:                                                                   '
'                                                                           '
'    Type all the regular DOS commands in the text box input and they are   '
'    executed with the results displayed in the top portion of the display. '
'                                                                           '
'  Audit:                                                                   '
'                                                                           '

Public Class Form1

    'Note - because the spawned process is running in a different thread, the only way
    'for it to write to a control in this process is to use a delegate.

    Private WithEvents MyProcess As Process

    Private Delegate Sub AppendStdOutDelegate(ByVal text As String)
    Private Delegate Sub AppendStdErrDelegate(ByVal text As String)

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Me.AcceptButton = ExecuteButton

        MyProcess = New Process

        With MyProcess.StartInfo
            .FileName = "CMD.EXE"
            .UseShellExecute = False
            .CreateNoWindow = True
            .RedirectStandardInput = True
            .RedirectStandardOutput = True
            .RedirectStandardError = True
        End With

        MyProcess.Start()

        MyProcess.BeginErrorReadLine()      'start async read on stderr
        MyProcess.BeginOutputReadLine()     'start async read on stdout

        AppendStdOut("Process Started at: " & MyProcess.StartTime.ToString)

    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

        MyProcess.StandardInput.WriteLine("EXIT") 'send an EXIT command to the Command Prompt
        MyProcess.StandardInput.Flush()
        MyProcess.Close()

    End Sub

    Private Sub MyProcess_ErrorDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles MyProcess.ErrorDataReceived

        AppendStdErr(vbCrLf & "Error: " & e.Data)

    End Sub

    Private Sub MyProcess_OutputDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles MyProcess.OutputDataReceived

        AppendStdOut(vbCrLf & e.Data)

    End Sub

    Private Sub ExecuteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExecuteButton.Click

        Submit(InputTextBox.Text)
        InputTextBox.Text = ""

    End Sub

    Private Sub AppendStdOut(ByVal text As String)

        If txtStdOut.InvokeRequired Then
            Dim myDelegate As New AppendStdOutDelegate(AddressOf AppendStdOut)
            Me.Invoke(myDelegate, text)
        Else
            txtStdOut.AppendText(text)
        End If

    End Sub

    Private Sub AppendStdErr(ByVal text As String)

        If txtStdOut.InvokeRequired Then
            Dim myDelegate As New AppendStdErrDelegate(AddressOf AppendStdErr)
            Me.Invoke(myDelegate, text)
        Else
            txtStdErr.AppendText(text)
        End If

    End Sub

    Private Sub Submit(cmd As String)

        MyProcess.StandardInput.WriteLine(cmd)
        MyProcess.StandardInput.Flush()

    End Sub

End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.