Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. running DOS exe using Process.Start

running DOS exe using Process.Start

Scheduled Pinned Locked Moved Visual Basic
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johnjsm
    wrote on last edited by
    #1

    Hi, When I run a DOS command line program it will work on a file that is located in the root of C:\ but if I try to run it on a file on my desktop nothing happens. Is there any way to get this to work.

    S K C D 4 Replies Last reply
    0
    • J johnjsm

      Hi, When I run a DOS command line program it will work on a file that is located in the root of C:\ but if I try to run it on a file on my desktop nothing happens. Is there any way to get this to work.

      S Offline
      S Offline
      sumit7034
      wrote on last edited by
      #2

      Try this Process.Start("cmd") Vote the answer if it is helpful

      J 1 Reply Last reply
      0
      • J johnjsm

        Hi, When I run a DOS command line program it will work on a file that is located in the root of C:\ but if I try to run it on a file on my desktop nothing happens. Is there any way to get this to work.

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #3

        include the full path to your program.

        Greetings from Germany

        1 Reply Last reply
        0
        • S sumit7034

          Try this Process.Start("cmd") Vote the answer if it is helpful

          J Offline
          J Offline
          johnjsm
          wrote on last edited by
          #4

          This is the code I am using

          'myProcess.StartInfo.FileName = "C:\Program Files\PDFcheck\pdffonts.exe " 'Full pathname to including file name
          'myProcess.StartInfo.Arguments = filename ' If the program takes args as string
          'myProcess.StartInfo.CreateNoWindow = True ' Does not create a window DOS program
          'myProcess.StartInfo.UseShellExecute = False ' Must be false to redirect output
          'myProcess.StartInfo.RedirectStandardOutput = True
          'myProcess.Start() ' Start the DOS program
          'myProcess.WaitForExit() ' Wait until it completes before moving on
          'prgOutput = myProcess.StandardOutput.ReadToEnd ' Get the DOS output
          'pdffonts = prgOutput
          'f.Close()

          1 Reply Last reply
          0
          • J johnjsm

            Hi, When I run a DOS command line program it will work on a file that is located in the root of C:\ but if I try to run it on a file on my desktop nothing happens. Is there any way to get this to work.

            C Offline
            C Offline
            Chinners
            wrote on last edited by
            #5

            Could it be that the filepath you are supplying contains spaces? If it is a dos program, they generally don't support spaces within filenames, and "c:\documents and settings\user\desktop" does contain spaces. You could try: c:\docume~1\user\desktop\filename.ext to see if this is the problem.

            J 1 Reply Last reply
            0
            • C Chinners

              Could it be that the filepath you are supplying contains spaces? If it is a dos program, they generally don't support spaces within filenames, and "c:\documents and settings\user\desktop" does contain spaces. You could try: c:\docume~1\user\desktop\filename.ext to see if this is the problem.

              J Offline
              J Offline
              johnjsm
              wrote on last edited by
              #6

              is there a way to convert the path from the standard to the dos path version within vb.net

              C 1 Reply Last reply
              0
              • J johnjsm

                is there a way to convert the path from the standard to the dos path version within vb.net

                C Offline
                C Offline
                Chinners
                wrote on last edited by
                #7

                you can go here: http://bytes.com/forum/thread349072.html[^] or copy/paste :)

                Private Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As String, ByVal lpszShortPath As System.Text.StringBuilder, ByVal cchBuffer As Integer) As Integer
                Private Const MAX_PATH As Integer = 260
                Public Function ShortFileName(ByVal LongFileName As String) As String
                Dim ShortPath As New System.Text.StringBuilder(MAX_PATH)
                Dim BufferSize As Integer = GetShortPathName(LongFileName, ShortPath, ShortPath.Capacity)
                Return ShortPath.ToString
                End Function

                J 1 Reply Last reply
                0
                • J johnjsm

                  Hi, When I run a DOS command line program it will work on a file that is located in the root of C:\ but if I try to run it on a file on my desktop nothing happens. Is there any way to get this to work.

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Ignore everything you've just been told. Though, Jasey9 got it partially correct and his solution is technically correct, but completely unnecessary. You have to enclose the full path of the file your passing to the DOS app in double quotes. Something like this:

                  someApp.exe "C:\\Documents and Settings\\userName\\Desktop\\Some Folder\\File.txt"
                  

                  What your code is doing is passing this:

                  someApp.exe C:\\Documents and Settings\\userName\\Desktop\\Some Folder\\File.txt
                  

                  Notice that there are no quotes. Since command line arguments are parsed using the "space" character as a delimiter, you've actually passed 4 arguments to the app, not 1. Enclosing any item, not necessarily path names, in double quotes treats the contents of the quotes as a single argument. So, in your code, you have to add double quotes to both ends of the path that your passing in the Arguments property of your Process object.

                  Public Shared Function FixupCommandlineParameter(ByVal s As String) As String
                  Return String.Format("""{0}""", s)
                  End Function

                  myProcess.StartInfo.Arguments = FixupCommandlineParameter(filename)
                  

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007, 2008

                  J 1 Reply Last reply
                  0
                  • C Chinners

                    you can go here: http://bytes.com/forum/thread349072.html[^] or copy/paste :)

                    Private Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As String, ByVal lpszShortPath As System.Text.StringBuilder, ByVal cchBuffer As Integer) As Integer
                    Private Const MAX_PATH As Integer = 260
                    Public Function ShortFileName(ByVal LongFileName As String) As String
                    Dim ShortPath As New System.Text.StringBuilder(MAX_PATH)
                    Dim BufferSize As Integer = GetShortPathName(LongFileName, ShortPath, ShortPath.Capacity)
                    Return ShortPath.ToString
                    End Function

                    J Offline
                    J Offline
                    johnjsm
                    wrote on last edited by
                    #9

                    Perfect. Thanks a million for your help.

                    1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      Ignore everything you've just been told. Though, Jasey9 got it partially correct and his solution is technically correct, but completely unnecessary. You have to enclose the full path of the file your passing to the DOS app in double quotes. Something like this:

                      someApp.exe "C:\\Documents and Settings\\userName\\Desktop\\Some Folder\\File.txt"
                      

                      What your code is doing is passing this:

                      someApp.exe C:\\Documents and Settings\\userName\\Desktop\\Some Folder\\File.txt
                      

                      Notice that there are no quotes. Since command line arguments are parsed using the "space" character as a delimiter, you've actually passed 4 arguments to the app, not 1. Enclosing any item, not necessarily path names, in double quotes treats the contents of the quotes as a single argument. So, in your code, you have to add double quotes to both ends of the path that your passing in the Arguments property of your Process object.

                      Public Shared Function FixupCommandlineParameter(ByVal s As String) As String
                      Return String.Format("""{0}""", s)
                      End Function

                      myProcess.StartInfo.Arguments = FixupCommandlineParameter(filename)
                      

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                           2006, 2007, 2008

                      J Offline
                      J Offline
                      johnjsm
                      wrote on last edited by
                      #10

                      Excellent. Thanks Dave.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups