passing long filenames as arguments to command line

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm running a console application (ghostscript) by starting it as a process
with arguments.

The problem i'm having is that it's falling over when I pass a file
containing spaces in the filename or filepath.

Anyone know how to get around this? (i've tried putting the file in quotes,
but it doesn't seem to work e.g. -sPDFname#"filename")
 
I was adding the quotes in the wrong place. I was saying
-sPDFname#"filename" when I should have been saying "-sPDFname#filename"
 
I just posted a question regarding this, albeit with an always changing
number of arguments. This is how I've been able to get all the arguments
passed correctly, when the number of arguments is always static. Just
modify the 'applaunch.StartInfo.Arguments' line to adjust the number of
arguments accordingly. Each space between arguments, or even in a
filename/path, represents an increase in arrayCount. Let me know how it
goes...


Dim applaunch As Process = New Process()
Dim arrayCount As Integer, appArgs() As String

'pull external exe path/name and args into array, then count array items
appArgs = System.Environment.GetCommandLineArgs
For arrayCount = 0 To UBound(appArgs)
Next arrayCount

applaunch.StartInfo.FileName = appArgs(1)
applaunch.StartInfo.Arguments = appArgs(2) & " " & appArgs(3) & " " &
appArgs(4)
 
Back
Top