Embedding file names in Linux Shell Command


I am using ghostscript to merge a list of pdf files into one file. I have some code similar to the following:

for a = 0 to listbox1.rowcount-1

s.execute ("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=done.pdf   trim(listbox1.list(a)) + .pdf")

next a

The list of files I would like to merge into done.pdf is in listbox1. This code does not work, of course. How do you embed a variable into a shell command?


You concatenate a string in Xojo like this:

dim s as string = "prefix " + someStringVar + " suffix"


In my code:

dim s as shell

I was just giving you an example of how to concatenate a string in Xojo and just picked “s” arbitrarily as the variable name. Isn’t that what you were looking for?


I tried that and it didn’t work.


For example:

s.execute (“gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=done.pdf” + trim(listbox1.list(a)) + “.pdf”)

[quote=199486:@Stuart Travis]
s.execute (“gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=done.pdf” + trim(listbox1.list(a)) + “.pdf”)[/quote]

That looks like it should work for you. Does it not?


That code does not work.

Well there is the space after the done.pdf and the quotation mark that needs to be added.

s.execute("gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=done.pdf " + trim(listbox1.list(a)) + ".pdf")

I’m not sure entirely if that’s it, but it looks like a culprit if its in the code in your program.


That is a typo that does not exist in my code. Good catch though. I simplified my code for presentation purposes.

@Stuart Travis

I figured as much with the code. Can we try a different route and get a look at the exact command line presentation with this code and the error if any:

Dim cmd as String for a = 0 to listbox1.rowcount-1 cmd="gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=done.pdf "+ trim(listbox1.list(a)) + .pdf" msgbox "Cmd: " + cmd s.execute(cmd) If s.errorcode=0 Then msgbox "Complete: " + s.result Else msgbox "Error: " + str(s.errorcode) End If next a

It’s worth noting that if your file names have spaces in them, you either need to enclose team in quotes or escape them…

[code]cmd=“gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=done.pdf “”” + trim(listbox1.list(a)) + .pdf"""

cmd=“gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=done.pdf " + trim(listbox1.list(a)).ReplaceAll(” “,”\ “) + .pdf”[/code]