INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Exec command in Windows

Exec command in Windows

(OP)
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
 

RE: Exec command in Windows

(OP)
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.

RE: Exec command in Windows

(OP)
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"


 

RE: Exec command in Windows

(OP)
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.  

RE: Exec command in Windows

(OP)
One final question

How do I trap errors in the command being executed with

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

Thanks

Andrew

RE: Exec command in Windows

(OP)
Hah!

I read the manual

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

Andrew

RE: Exec command in Windows

Quote (fdservices):


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

set my_cmd "|cmd.exe /c DIR C:\\\"Program Files\"\\G* /B"

puts "Now executing the command '$my_cmd':\n"

set f [open $my_cmd "r"]

#process command output
while {[gets $f line] != -1} {
  # print line
  puts $line
}

close $f
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
 

RE: Exec command in Windows

(OP)
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

RE: Exec command in Windows

Hi fdservices,
It's nice when it works and I was glad to help you.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close