Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exec command in Windows

Status
Not open for further replies.

fdservices

IS-IT--Management
Mar 10, 2005
52
FR
I need to execute the following command in windows:

"C:\Program Files\gs\gs9.04\bin\gswin32c.exe" -sDEVICE=pdfwrite -dMaxSubsetPct=100 -dPDFSETTINGS=/ebook -sOutputFile="out.pdf" -dNOPAUSE -dQUIET -dBATCH "$file"

If I exec the command in tcl then it fails with odd errors.
If I run the command from the command line it is fine.
If I put the command in a batch file and pass the path/filename to the batch it fails, because the path is a UNC path and cannot be accessed by the batch file.

The best solution would be to run the command within the tcl script, but I have tried eval [concat..., and quoting everything and it just won't play.

Does any one have any more ideas to try out?

Thanks

Andrew
 
Tried that with no luck. Here is the output

pwd = C:\tmp
command = "C:\Program Files\gs\gs9.04\bin\gswin32c.exe" -sDEVICE=pdfwrite -dMaxSubsetPct=100 -dPDFSETTINGS=/ebook -sOutputFile="out.pdf" -dNOPAUSE -dQUIET -dBATCH "20120327195139.pdf"

The error is

couldn't open ""C:\Program Files\gs\gs9.04\bin\gswin32c.exe" -sDEVICE=pdfwrite -dMaxSubsetPct=100 -dPDFSETTINGS=/ebook -sOutputFile="out.pdf" -dNOPAUSE -dQUIET -dBATCH "20120327195139.pdf"":no such file or folder.
 
OK it is working now, I had to double quote the path \s and put $command in inverted commas

set f [open "$command" "r"]

Now the error is the same as when I ran the command with exec if I remember correctly. It is from Ghostscript:

could not open the file "out.pdf"


 
Success, removed the quotes from out.pdf and it ran.

Not a problem for me, but I wonder how to pass a filename with spaces as the output file.

Thanks for the help.
 
One final question

How do I trap errors in the command being executed with

set f [open "$command" "r"]

Thanks

Andrew
 
Hah!

I read the manual

The errors are returned with the close command, so can be caught there.

Andrew
 
fdservices said:
but I wonder how to pass a filename with spaces as the output file
Use escaped quotes within a string - for example:
process_command.tcl
Code:
[COLOR=#804040][b]set[/b][/color] my_cmd [COLOR=#ff00ff]"|cmd.exe /c DIR C:[/color][COLOR=#6a5acd]\\\"[/color][COLOR=#ff00ff]Program Files[/color][COLOR=#6a5acd]\"\\[/color][COLOR=#ff00ff]G* /B"[/color]

[COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"Now executing the command '[/color][COLOR=#008080]$my_cmd[/color][COLOR=#ff00ff]':[/color][COLOR=#6a5acd]\n[/color][COLOR=#ff00ff]"[/color]

[COLOR=#804040][b]set[/b][/color] f [[COLOR=#804040][b]open[/b][/color] [COLOR=#008080]$my_cmd[/color] [COLOR=#ff00ff]"r"[/color]]

[COLOR=#0000ff]#process command output[/color]
[COLOR=#804040][b]while[/b][/color] {[[COLOR=#804040][b]gets[/b][/color] [COLOR=#008080]$f[/color] line] != -[COLOR=#ff00ff]1[/color]} {
[COLOR=#0000ff]  # print line[/color]
  [COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$line[/color]
}

[COLOR=#804040][b]close[/b][/color] [COLOR=#008080]$f[/color]
Output:
Code:
C:\Users\Roman\Work>tclsh process_command.tcl
Now executing the command '|cmd.exe /c DIR C:\"Program Files"\G* /B':

gedit
gforth
gfortran
Ghostgum
gnubg
Google
Groovy
gs
 
It always seems to be so easy when you say it.

Seriously, I am very grateful for you help, my programme is working perfectly now.

Andrew
 
Hi fdservices,
It's nice when it works and I was glad to help you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top