Sign in to follow this  
Followers 0
zimzum

@ComSpec error

9 posts in this topic

Posted Image

Anyone have a clue whats wrong with my syntax there?

(Line Code)

RunWait(@COMSPEC & "C:\CJIS Data\TrueCrypt\TrueCrypt.exe /q background /s /p """$pw""" /e /m ro /m rm /v ""CJISDATA.ENC""")

(End Line Code)

I am trying to output to command line; a variable sandwitched between two static lines of text.

Example output: (Variable as its value in red)

C:\CJIS Data\TrueCrypt\TrueCrypt.exe /q background /s /p "fubar" /e /m ro /m rm /v "CJISDATA.ENC"

Anyone mind giving me the proper syntax with the "'s, as I think that is where I am getting tripped up.

Thanks!

Share this post


Link to post
Share on other sites



zimzum welcome to Autoit. It is easy if you use a combination of sigle quote and double quotes.

RunWait(@COMSPEC & '"C:\CJIS Data\TrueCrypt\TrueCrypt.exe" /q background /s /p "' & $pw & '" /e /m ro /m rm /v "CJISDATA.ENC"')

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

zimzum welcome to Autoit. It is easy if you use a combination of sigle quote and double quotes.

RunWait(@COMSPEC & '"C:\CJIS Data\TrueCrypt\TrueCrypt.exe" /q background /s /p "' & $pw & '" /e /m ro /m rm /v "CJISDATA.ENC"')

Thank you very much, Sir, your cooperation in this matter is greatly appriciated.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

To jump from a string to non string you have to concatenate properly, which you're not doing yet. For example:

$var = "Hello"
MsgBox(0, "Example", $var & " World"); Notice the & symbol

This is how to properly concatenate strings.

Other examples:

$var = "variables"
MsgBox(0, 'Example', 'There are "' & $var & '" in here.')
MsgBox(0, 'Example', 'Concatenating strings' & 'Is the same as ' & $var & '.')
MsgBox(0, 'Example', 'This string has "quotation" marks in it' & " and this string has 'apostrophes' in it.")

*Edit: Oops a little too slow. Something else I noticed though, guess it's not a problem yet but you should have a space in your string after @ComSpec, otherwise when evaluated it could end up looking something like C:\WINDOWS\system32\cmd.exeC:\File.exe and I'm sure you can see how that would be a problem.

Edited by Saunders

Share this post


Link to post
Share on other sites

*Edit: Oops a little too slow. Something else I noticed though, guess it's not a problem yet but you should have a space in your string after @ComSpec, otherwise when evaluated it could end up looking something like C:\WINDOWS\system32\cmd.exeC:\File.exe and I'm sure you can see how that would be a problem.

Are you saying that I should have...

RunWait(@COMSPEC & '" C:\CJIS Data\"

instead of...

RunWait(@COMSPEC & '"C:\CJIS Data\

?

Share this post


Link to post
Share on other sites

Hrm, Running into another question here. I half expected a flurry of command windows to open and close, and no such luck. Should they? I would like to see that it is doing somthing other than just running through endless loops and not running my commands.

Also, what is the 'deafault' dir of where the CMD runs from? "C:\Windows\System32" ? I need a file to be where it executes so that it finds it.

Share this post


Link to post
Share on other sites

Okay, so I've been doing some more work on this @COMSPEC and this is what I have...

$run = '"C:\CJISData\TrueCrypt\TrueCrypt.exe /q background /p "' & $pw & '" /e /l l /m ro /m rm /v "CJISDATA.ENC"'

Run(@COMSPEC & " /c " & $run)

when I run the script, it pops open a CMD box (Well, many many of them, since I used Run, instead of RunWait), and the response I get from TrueCrypt.exe is not the same if I type...

C:\CJISData\TrueCrypt\TrueCrypt.exe /q background /p "fubar" /e /l l /m ro /m rm /v "CJISDATA.ENC"

into a command window.

I added in a...

MsgBox(0, "My Second Script!", $run )

as a diagnostics tool, and it seems to show the correct command line.

If you have any intuition as to my problem, it would be greatly appriciated.

Share this post


Link to post
Share on other sites

You may also want to set the command prompt in single line command mode by using the /c switch

RunWait(@ComSpec & ' /c "C:\CJIS Data\TrueCrypt\TrueCrypt.exe" /q background /s /p "' & $pw & '" /e /m ro /m rm /v "CJISDATA.ENC"')oÝ÷ Ú«¨µéÚ

The above example shows the working directory of the command prompt as current working directory inherited, @SystemDir and @UserProfileDir in the order of execution. On the last attempt, you could execute a file using just a filename located in @UserProfileDir as it is where the command prompt is working in.

:)

Share this post


Link to post
Share on other sites

You may also want to set the command prompt in single line command mode by using the /c switch

RunWait(@ComSpec & ' /c "C:\CJIS Data\TrueCrypt\TrueCrypt.exe" /q background /s /p "' & $pw & '" /e /m ro /m rm /v "CJISDATA.ENC"')ƒoÝŠ÷ Ú«¨µéÚ™

The above example shows the working directory of the command prompt as current working directory inherited, @SystemDir and @UserProfileDir in the order of execution. On the last attempt, you could execute a file using just a filename located in @UserProfileDir as it is where the command prompt is working in.

:)

the /k didn't leave the code in the window (no big deal, I was having some other major issues that I was worried about)

Anywho, I got the code to work. Had some misplaced "'s in there.

$run = '"C:\CJISData\TrueCrypt\TrueCrypt.exe /q background /p "' & $pw & '" /e /l l /m ro /m rm /v "CJISDATA.ENC"'

Should have been

$run = 'C:\CJISData\TrueCrypt\TrueCrypt.exe /q background /p "' & $pw & '" /e /m ro /m rm /v "c:\CJISData\TrueCrypt\CJISDATA.ENC"'

I circumvented worring about the default working directory by putting a absolute link to the file in question...

Thanks for the help everyone!

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