celestialspring Posted September 7, 2009 Share Posted September 7, 2009 Hi Guys, This is my dos command (run in cmd.exe): D:\Documents and Settings\bt>"D:\Program Files\PDFTK Builder\pdftk.exe" "D:\Documents and Settings\bt\Desktop\front.pdf" stamp "D:\Documents and Settings\bt\Desktop\back.pdf" output "D:\Documents and Settings\bt\Desktop\output.pdf" I am trying to run this with Autoit, I am getting an error: $front = "D:\Documents and Settings\bt\Desktop\front.pdf" $prog = "D:\Program Files\PDFTK Builder\pdftk.exe" $back = "D:\Documents and Settings\bt\Desktop\back.pdf" $output = "D:\Documents and Settings\bt\Desktop\output.pdf" ShellExecutewait($prog & " " & $front & " " & stamp & " " & $back & " " & output & " " & $output) OR RunWait(@ComSpec & " " & $prog & " " & $front & " " & stamp & " " & $back & " " & output & " " & $output) what am I doing wrong? Link to comment Share on other sites More sharing options...
99ojo Posted September 7, 2009 Share Posted September 7, 2009 Hi, this should work: ShellExecute (0,"", """" & $prog & """" & " " & """" & $front & """" & " " & " stamp" & " " & """" & $back & """" & " " & "output" & " " & """" & $output & """") ;-)) Stefan Link to comment Share on other sites More sharing options...
jvanegmond Posted September 7, 2009 Share Posted September 7, 2009 There are two problems in your script.One:$a = "Something" ; $a contains Something RunWait(@ComSpec & " " & $a) ; This will run cmd.exe Something ( Not cmd.exe "Something" )So instead do this:$a = '"Something"' ; $a contains "Something" RunWait(@ComSpec & " " & $a) ; This will run cmd.exe "Something"Or a little more complicated:RunWait("cmd.exe ""Something""")Two:Try running this:cmd.exe notepad.exeYou'll see notepad.exe does not open! : )Probably same problem with your script. This is a solution:cmd.exe /c start notepad.exeOr if you want the cmd.exe to stay when it's ready do this:cmd.exe /k start notepad.exe github.com/jvanegmond Link to comment Share on other sites More sharing options...
celestialspring Posted September 7, 2009 Author Share Posted September 7, 2009 Unfortunately both approaches suggested above dont work. Most of the times when the script seems to work it simply opens cmd.exe but does nothing after that. Look at the different variations i have tried: $prog = "C:\Program Files\PDFTK Builder\pdftk.exe" $orgfile = "c:\report.pdf" $stampfile = "C:\PDF\xyz 2 pgs.pdf" $outputfile = "C:\stampedreport.pdf" ;~ RunWait("cmd.exe /k" & $prog & " " & $orgfile & " stamp " & $stampfile & " output " & $outputfile) ;~ RunWait(@ComSpec & " " & "C:\Program Files\PDFTK Builder\pdftk.exe" & " " & "c:\report.pdf" & " " & "stamp" & " " & "C:\PDF\xyz 2 pgs.pdf" & " " & "output" & " " & "C:\stampedreport.pdf") ;~ ShellExecute(@ComSpec,"",""," " & "C:\Program Files\PDFTK Builder\pdftk.exe" & " " & "c:\report.pdf" & " " & "stamp" & " " & "C:\PDF\Xyz 2 pgs.pdf" & " " & "output" & " " & "C:\stampedreport.pdf") ;~ ShellExecute ("cmd.exe","", """" & $prog & """" & " " & """" & $orgfile & """" & " " & " stamp" & " " & """" & $stampfile & """" & " " & "output" & " " & """" & $outputfile & """") Run(@ComSpec & " " & """" & $prog & """" & " " & """" & $orgfile & """" & " " & " stamp" & " " & """" & $stampfile & """" & " " & "output" & " " & """" & $outputfile & """") It doesnt even work with straight paths let alone the variable paths. Link to comment Share on other sites More sharing options...
Mobius Posted September 8, 2009 Share Posted September 8, 2009 $front = "front.pdf" $prog = '"'& @PROGRAMFILESDIR &'\PDFTK Builder\pdftk.exe"' $back = "back.pdf" $output = "output.pdf" ;Runwait your app direct. IF NOT MsgBox(36,"Exec?",$Prog &" "& $Front &" stamp "& $back &" output "& $output ) THEN RunWait($Prog &" "& $Front &" stamp "& $back &" output "& $output ,@DESKTOPDIR) ENDIF ;Runwait your app through a command shell $prog = '"'& @COMSPEC &'" /C "'& StringTrimLeft($prog,1) IF NOT MsgBox(36,"Exec?",$Prog &" "& $Front &" stamp "& $back &" output "& $output ) THEN RunWait($Prog &" "& $Front &" stamp "& $back &" output "& $output ,@DESKTOPDIR) ENDIF Just curious celestialspring, but does 'pdftk.exe' have to be executed through a cmd shell? Ie) because it is a cui application? Link to comment Share on other sites More sharing options...
celestialspring Posted September 8, 2009 Author Share Posted September 8, 2009 @Mobius Mate, it doesn't need to be done thru cmd.exe but I dont know how else would I be able to pass the command line arguments with the program. Here is something that works (only with hard paths - no variables) RunWait('C:\Program Files\PDFTK Builder\pdftk.exe "c:\report.pdf" stamp "C:\PDF\dp.pdf" output "C:\stampedreport.pdf"') The challenge is now to run the program with variables. cheers. Link to comment Share on other sites More sharing options...
Mobius Posted September 8, 2009 Share Posted September 8, 2009 (edited) @OP What's this then? re fried beans? $front = '"'& @DESKTOPDIR &'\front.pdf"' $prog = '"'& @PROGRAMFILESDIR &'\PDFTK Builder\pdftk.exe"' $back = '"'& @DESKTOPDIR &'\back.pdf"' $output = '"'& @DESKTOPDIR &'\output.pdf"' RunWait($Prog &" "& $Front &" stamp "& $back &" output "& $output) btw, you only need to execute cmd.exe (command shell) when you need the stdio window, or need to make use of cmd specific control switches and functions, or you are calling another program that uses command output and wish to view it without reading the stdout to a variable. not for executing any old binary. If a program supports cmdline args / switches then just pass them to it, but make sure you pass them correctly following the rules of execution for the system. Ed *Combustion* Ed: you guys do know that you can click the function and macro names of any code inside Au3 tags to get online help on it don't you? Edited September 8, 2009 by Mobius Link to comment Share on other sites More sharing options...
celestialspring Posted September 8, 2009 Author Share Posted September 8, 2009 This one works, Mate. Thanks a lot. You have saved me a lot of grief. Thanks. cs PS: I do read the help files but I am a finance professional, I don't understand a lot of coding Link to comment Share on other sites More sharing options...
jvanegmond Posted September 8, 2009 Share Posted September 8, 2009 celestialspring, you missed what I was explaining in my post so just for clarity I'm making a follow up. Try this: $prog = '"C:\Program Files\PDFTK Builder\pdftk.exe"' ; paths with spaces must be enclosed in " quotes " $orgfile = "c:\report.pdf" $stampfile = '"C:\PDF\xyz 2 pgs.pdf"' $outputfile = "C:\stampedreport.pdf" ;Run("cmd.exe /k" & $prog & " " & $orgfile & " stamp " & $stampfile & " output " & $outputfile) ; you forgot a space after the /k here $runMe = "cmd.exe /k " & $prog & " " & $orgfile & " stamp " & $stampfile & " output " & $outputfile ConsoleWrite($runMe & @CRLF) ; For debugging! Run($runMe) github.com/jvanegmond Link to comment Share on other sites More sharing options...
Mobius Posted September 8, 2009 Share Posted September 8, 2009 This one works, Mate. Thanks a lot.You have saved me a lot of grief.Thanks.csPS: I do read the help files but I am a finance professional, I don't understand a lot of coding No offense intended cs, There are so many that do not. Try and stay away from hard coded paths wherever possible, and as already stated, the rulesof the system dictate that paths with spaces must be enclosed in literal quotes.Its a pain in the ass particularly when a large number of system folders use this skullfuggery Vlad Link to comment Share on other sites More sharing options...
celestialspring Posted September 8, 2009 Author Share Posted September 8, 2009 Thank you, Manadar and Mobius. Now I understand the concept. Regards,cs Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now