Results 1 to 8 of 8

Thread: [RESOLVED] Can't access files below root when using Process to run a command line program.

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    7

    Resolved [RESOLVED] Can't access files below root when using Process to run a command line program.

    Hello,

    I am trying to create a program that downloads audio files via FTP, converts the audio to mp2 if necessary and copies them to a certain directory for consumption by our automation system. (I am a radio station engineer.)

    I am using the open source converter FFMpeg to convert audio files to mp2. This is a command line exectuted program. Here is the command line that I use to execute the external program with the input and output audio files at the root level:

    cmd.exe /k ""C:\New Folder\ffmpeg.exe" -i "C:\Test.mp3" -y "C:\Test.mp2""

    This command line works correctly whether I am using Shell() or System.Diagnostics.Process (Process) to execute the external program. I am going the Process route so I can know when the conversion has finished.

    Now, I really don't want to use the root directory for this but when I go below root with this line using Process the external program will not execute:

    cmd.exe /k ""C:\New Folder\ffmpeg.exe" -i "C:\New Folder\Test.mp3" -y "C:\New Folder\Test.mp2""

    Can anyone tell me why that line will not work with Process though it works as expected with Shell()? I can't figure out how to stop the external program to get some feedback as to what its problem is.

    Thanks

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Can't access files below root when using Process to run a command line program.

    Can you post code? I think it should be something along the lines of
    Code:
    Dim fileName As String = "C:\New Folder\ffmpeg.exe"
    Dim args As String = "-i ""C:\New Folder\Test.mp3"" -y ""C:\New Folder\Test.mp2"""
    Dim info As New ProcessStartInfo(filename, args)
    Dim p As Process = Process.Start(info)
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    7

    Re: Can't access files below root when using Process to run a command line program.

    I'll be happy to post the code. The code I am using is what I have found online. I have tried a couple of different versions. Here is the pertinent code in subroutines. Cmd1 is the program name, cmd2 has the arguments for the program:

    The first one is from Microsoft documentation
    Private Sub CurrentProc(ByVal cmd1 As String, ByVal cmd2 As String)
    Dim procID As Integer
    Dim newProc As Diagnostics.Process
    newProc = Diagnostics.Process.Start(cmd1.ToString, cmd2.ToString)
    procID = newProc.Id
    newProc.WaitForExit()
    Dim procEC As Integer = -1
    If newProc.HasExited Then
    procEC = newProc.ExitCode
    End If
    MsgBox("Process with ID " & CStr(procID) & _
    " terminated with exit code " & CStr(procEC))

    End Sub

    Private Sub CurrentProc2(ByVal cmd1 As String, ByVal cmd2 As String)
    Dim process As System.Diagnostics.Process = Nothing
    Dim processStartInfo As System.Diagnostics.ProcessStartInfo
    processStartInfo = New System.Diagnostics.ProcessStartInfo()

    processStartInfo.FileName = cmd1 '"notepad.exe" 'program to run

    If System.Environment.OSVersion.Version.Major >= 6 Then
    ' Run as admin on Windows Vista or higher
    processStartInfo.Verb = "runas"
    End If
    processStartInfo.Arguments = cmd2 '"C:\test.txt" 'file to open as argument
    processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
    processStartInfo.UseShellExecute = True

    Try
    process = System.Diagnostics.Process.Start(processStartInfo)
    Catch ex As Exception
    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Finally

    If Not (process Is Nothing) Then
    process.Dispose()
    End If

    End Try


    End Sub

    Both subroutines had the same net result. All of the logic for executing the external program is in those subroutines.

    Thanks

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Can't access files below root when using Process to run a command line program.

    Did you try the code I posted?
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    7

    Re: Can't access files below root when using Process to run a command line program.

    Hello Wild Bill,

    Sorry for the delay. I've been out of the office. Yes your code does work. Now I need to be able to have it terminate and trap the return value to see if it was successful.

    Thanks

  6. #6
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Can't access files below root when using Process to run a command line program.

    Does this work:

    Code:
    Dim fileName As String = "C:\New Folder\ffmpeg.exe"
    Dim args As String = "-i ""C:\New Folder\Test.mp3"" -y ""C:\New Folder\Test.mp2"""
    Dim info As New ProcessStartInfo(fileName, args)
    Dim p As Process = Process.Start(info)
    p.WaitForExit()
    Console.WriteLine(p.ExitCode)
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    7

    Re: Can't access files below root when using Process to run a command line program.

    Yes that work's just fine. I added the p.WaitForExit() code after the last reply but just kept the message box approach from the other code and it works great. The problem was that Process was expecting quotes where the cmd.exe wasn't which I am sure you figured out to begin with.

    Now off to play with FTP. Thanks again for the help.

  8. #8
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Can't access files below root when using Process to run a command line program.

    No problem, please mark the thread resolved by going to "Thread Tools" > "Mark Thread Resolved"
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width