Jump to content

Running dos command


Recommended Posts

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

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.exe

You'll see notepad.exe does not open! : )

Probably same problem with your script. This is a solution:

cmd.exe /c start notepad.exe

Or if you want the cmd.exe to stay when it's ready do this:

cmd.exe /k start notepad.exe
Link to comment
Share on other sites

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

$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?

wtfpl-badge-1.png

Link to comment
Share on other sites

@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

@OP

:D 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 by Mobius

wtfpl-badge-1.png

Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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 :D

No offense intended cs, There are so many that do not. :D

Try and stay away from hard coded paths wherever possible, and as already stated, the rules

of 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 :D

Vlad

wtfpl-badge-1.png

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...