running DOS exe using Process.Start
-
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.
-
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.
-
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() -
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.
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.
-
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.
-
is there a way to convert the path from the standard to the dos path version within vb.net
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 -
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.
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 FunctionmyProcess.StartInfo.Arguments = FixupCommandlineParameter(filename)
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
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 -
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 FunctionmyProcess.StartInfo.Arguments = FixupCommandlineParameter(filename)
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008