Sign in to follow this  
Followers 0
scriptjunkie

Run or Runwait with quotes

4 posts in this topic

I am trying to run this command:

$programlocation = "c:\program files\app\app.exe"
$filetoprocess = "c:\program files\app\data.txt"
$output = "c:\program files\app\output.txt"
Run(@ComSpec & ' /k "' & $programlocation & '" options "' & $filetoprocess & '" > "'&$output&'"')

I keep getting a error that 'c:\program' is not valid.

If I copy the info to my clipboard and paste it to a oommand line, the command runs.

clipput("' & $programlocation & '" options "' & $filetoprocess & '" > "'&$output&'"')

I have to put quotes in my file directories because of spaces. However I can't seem to get multiple quotes to work correctly.

If I use only 1 set of quotes it works.

$programlocation = "c:\program files\app\app.exe"
$filetoprocess = "c:\data.txt"
$output = "c:\output.txt"
Run(@ComSpec & ' /k "' & $programlocation & '" options ' & $filetoprocess & ' > '&$output)

Maybe it's a limitation?

Thanks for your time looking at my problem.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is apparently due to the way cmd /c or /k handles quotes, see http://www.computerhope.com/cmd.htm for more information on that.

To "fix" it, try the following:

$programlocation = "c:\program files\app\app.exe"
$filetoprocess = "c:\program files\app\data.txt"
$output = "c:\program files\app\output.txt"
Run(@ComSpec & ' /k ""' & $programlocation & '" options "' & $filetoprocess & '" > "'&$output&'""')

Notice the double quoting, since the first and last characters are getting stripped, this would "preserve" them. So note, it is not a limitation of AutoIt, just the way cmd.exe works.

Edited by archgriffin

"Human kind cannot gain anything without first giving something in return, to obtain; something of equal value must be lost."The Help File is truly your friend.

Share this post


Link to post
Share on other sites

Great that worked... :) Thanks!!!

Share this post


Link to post
Share on other sites

I know that you got it working, but do you really need @ComSpec to run the app?


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
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
Sign in to follow this  
Followers 0