Sign in to follow this  
Followers 0
Carlos Villar

Executing command line aplications (and again)

14 posts in this topic

Hello everybody:

I'm trying to automate a backup with AutoIt (v 3.1.1) in Windows XP Professional. After having it done in %tmp%/Copia de Seguridad.zip I execute nerocmd.exe (command line version of Nero) to have it writed into DVD.

I first have tried with:

RunWait(@ComSpec & ' /c "C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd %tmp%"\Copia de Seguridad.zip" --force_erase_disc')

But I have nothing else than a flashing command promt window. I add > nerocmd.txt to read the reply, but the file it's empty. I execute it at the command promt and work.

I tried to simplify it, substituing the variable %tmp% with the actual value C:\Documents and Settings\Carlos\Configuración local\Temp :

RunWait(@ComSpec & ' /c "C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "C:\Documents and Settings\Carlos\Configuración local\Temp\Copia de Seguridad.zip" --force_erase_disc')

But I have exactly the same. A flashing command promt window, an empty nerocmd.txt and work at the command promt. Because now there is no variable, I tried stripping the @ComSpec & ' /c :

RunWait('"C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "C:\Documents and Settings\Carlos\Configuración local\Temp\Copia de Seguridad.zip" --force_erase_disc')

And works... I can have it working this way, but I would like use the %tmp% and I'm simply puzzle. Any comment would be appreciated.

See you,

Carlos Villar

Share this post


Link to post
Share on other sites



hi Carlos,

I've had many headaches trying to get the spacing and quotes right for some command line stuff to work and this is quite diffent from what i have done but maybe something here may help:

http://www.autoitscript.com/forum/index.ph...477&hl=a.b.ames

Saunders pointed out a few things to help me too.

BTW at the top of your statement you state you have

After having it done in %tmp%/Copia de Seguridad.zip I execute nerocmd.exe (command line version of Nero)

note the / , yet in your examples you use %tmp%\Copia de Seguridad.zip

maybe this is it (again not familiar with what product you are using).

also if you show exactly what you would type into the command line to run this manually vs the autoit code it maybe easier for someone here to spot something to help you.

Hope this helps a bit

A.B.Ames

Share this post


Link to post
Share on other sites

Your first example probably didn't work because %tmp% contains spaces, but you didn't include it in your quotes. Also, you need to use the ExpandEnvStrings option if you want to use %tmp% within a string.

Try this:

Opt("ExpandEnvStrings", 1)
 RunWait(@ComSpec & ' /c "C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "%tmp%\Copia de Seguridad.zip" --force_erase_disc')

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

RunWait('"C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "C:\Documents and Settings\Carlos\Configuración local\Temp\Copia de Seguridad.zip" --force_erase_disc')

And works... I can have it working this way, but I would like use the %tmp% and I'm simply puzzle. Any comment would be appreciated.

I had the same problem with spaces in the command (C:\Archivos de programa\). The following did the job for me. Remove the full path of the command and specify it as workingdir instead.

$command = 'NeroCmd.exe --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "C:\Documents and Settings\Carlos\Configuración local\Temp\Copia de Seguridad.zip" --force_erase_disc'
$workdir = "C:\Archivos de programa\Ahead\Nero\"

RunWait(@ComSpec & " /c " & $command, $workdir, @SW_HIDE)

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

the easiest way to find if a command line string is being parsed and passed to an external program correctly is to put the line in a message box window for you to see the outcome, if its right then it should be right for the external program

Edited by Rick

Who needs puzzles when we have AutoIt!!

Share this post


Link to post
Share on other sites

the easiest way to find if a command line string is being parsed and passed to an external program correctly is to put the line in a message box window for you to see the outcome, if its right then it should be right for the external program

unfortunately that's not correct. If you call RunWait(@ComSpec & " /c " & $command) you are actually executing: cmd.exe /c <your command>.

Now, cmd.exe is quite a bit picky about how you pass the parameters, especially if there are blanks in the path and/or the parameters.

This won't work: cmd /c c:\program files\test\notepad.exe

This won't work: cmd /c 'c:\program files\test\notepad.exe'

This will work: cmd /c "c:\program files\test\notepad.exe"

This will work: cmd /c "c:\program files\test\notepad.exe" text.txt

This won't work: cmd /c "c:\program files\test\notepad.exe" hello world.txt

This won't work: cmd /c "c:\program files\test\notepad.exe hello world.txt"

This won't work: cmd /c "c:\program files\test\notepad.exe" "hello world.txt"

However, this will work: cmd /c "c:\program files\test\notepad.exe" 'hello world.txt'

So, to pass a long command with commanline parameters (all possibly containing spaces), do the following you will have to quote the command with double quotes and the paramters with single quotes if there are spaces in it.

$command = '"C:\Archivos de programa\Ahead\Nero\NeroCmd.exe"'   ; single quote, then double quote !!
$params = "--write --drivename d --real --speed 4 --iso " & "'" & "Copia de Seguridad" & "'" & "--iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd" & "'" &  "C:\Documents and Settings\Carlos\Configuración local\Temp\Copia de Seguridad.zip" & "'" & "--force_erase_disc"

RunWait(@ComSpec & ' /c '  & $command & " " & $params)

The solution I provided first should work too.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

yes you are correct altho i was referring to the line being sent to nero, not to command.com


Who needs puzzles when we have AutoIt!!

Share this post


Link to post
Share on other sites

yes you are correct altho i was referring to the line being sent to nero, not to command.com

Ah, O.K. Probably I misinterpreted that...

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Hello A.B.Ames:

note the / , yet in your examples you use %tmp%\Copia de Seguridad.zip

maybe this is it (again not familiar with what product you are using).

You are right, but it was an error typing the post. I have my backup done in %tmp%\Copia de Seguridad.zip, just like in the examples. But I tend to write / in Windows instead of \ because of web addreses and Unix.

Thanks anyway, I see you did a detailed reading.

See you,

Carlos Villar

Share this post


Link to post
Share on other sites

Hello Skruge:

Your first example probably didn't work because %tmp% contains spaces, but you didn't include it in your quotes. Also, you need to use the ExpandEnvStrings option if you want to use %tmp% within a string.

Try this:

Opt("ExpandEnvStrings", 1)
 RunWait(@ComSpec & ' /c "C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "%tmp%\Copia de Seguridad.zip" --force_erase_disc')
I think ExpandEnvStrings option is't necessary because autoit isn't the one who's going to subtitute the %tmp% with the actual value, it's cmd.exe And althought the variable's actual value contais spaces, don't seem necessary to wrap the variable inside quotes. Why do I think this way? becouse a have:

$errorlevel = RunWait(@ComSpec & ' /c defrag c: -a > %tmp%\defrag.txt', "", @SW_HIDE)

in another script and works perfectly without ExpandEnvStrings option, and without further quotation, althought the variable's actual value includes spaces. Anyway I've tested your suggestions without luck.

Thanks for your time.

See you,

Carlos Villar

Share this post


Link to post
Share on other sites

Hello everybody:

I'm trying to automate a backup with AutoIt (v 3.1.1) in Windows XP Professional. After having it done in %tmp%/Copia de Seguridad.zip I execute nerocmd.exe (command line version of Nero) to have it writed into DVD.

I first have tried with:

RunWait(@ComSpec & ' /c "C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd %tmp%"\Copia de Seguridad.zip" --force_erase_disc')

But I have nothing else than a flashing command promt window. I add > nerocmd.txt to read the reply, but the file it's empty. I execute it at the command promt and work.

I tried to simplify it, substituing the variable %tmp% with the actual value C:\Documents and Settings\Carlos\Configuración local\Temp :

RunWait(@ComSpec & ' /c "C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "C:\Documents and Settings\Carlos\Configuración local\Temp\Copia de Seguridad.zip" --force_erase_disc')

But I have exactly the same. A flashing command promt window, an empty nerocmd.txt and work at the command promt. Because now there is no variable, I tried stripping the @ComSpec & ' /c :

RunWait('"C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "C:\Documents and Settings\Carlos\Configuración local\Temp\Copia de Seguridad.zip" --force_erase_disc')

And works... I can have it working this way, but I would like use the %tmp% and I'm simply puzzle. Any comment would be appreciated.

See you,

Carlos Villar

Hey Carlos,

I would like to put in my $.02 here, but please note that this might not be the best solution, just the one that makes sense to me.

First, I would like to take your initial code and use it as our base of reference, but i'll fix what I see if wrong with it. So the following will be our reference (note that I changed %tmp\"Copia De Seguridad.zip" to "%tmp%\Copia de Seguridad" because DOS doesn't always expand the variable value when it's part of a path unless it's under quotes)

RunWait(@ComSpec & ' /c  ' & '"C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "%tmp%\Copia de Seguridad.zip" --force_erase_disc')[/

The second thing I would like to address is that empty output file you have. if you added "2>&1" to your script, then both the standard output and the error output would be written to that file. For Example:

RunWait(@ComSpec & ' /c  ' & '"C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "%tmp%\Copia de Seguridad.zip" --force_erase_disc > c:\nerocmd.txt 2>&1')[/

I would also add the following to your code

if fileexist("c:\nerocmd.txt") then
runwait("notepad " &"c:\nerocmd.txt")
endif

Let me know if that helps, I hope I haven't confused you yet.


---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Share this post


Link to post
Share on other sites

Hello everybody:

Uff, this stuff is going me crazy! Note that I'm not an IT pro nor student, just a fun with limited BASIC, QBASIC, batch and Macro Scheduler scripts experience, wich is trying to redo and improve some old scripts for Windows Me into Windows XP. Until now I've just been able to work on the first two replies, I didn't expect so much and so quick. Furthermore, having to write in English doesn't make things easier. So, lets go!

Thinking that the problem is around cmd.exe and his subtitution of enviromental variables, I've think about two workarounds letting this to autoit that let me continue using variables:

RunWait('"C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "' & @TempDir & '\Copia de Seguridad.zip" --force_erase_disc')

Or if you prefer:

RunWait('"C:\Archivos de programa\Ahead\Nero\NeroCmd.exe" --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd "' & EnvGet("tmp") & '\Copia de Seguridad.zip" --force_erase_disc')

I'll continue reading your pots.

See you,

Carlos Villar

Share this post


Link to post
Share on other sites

This won't work: cmd /c "c:\program files\test\notepad.exe" "hello world.txt"

...

So, to pass a long command with commanline parameters (all possibly containing spaces), do the following you will have to quote the command with double quotes and the paramters with single quotes if there are spaces in it.

...

The solution I provided first should work too.

Hello /dev/null:

(Funny name :o )

Both of your examples worked without problems. First I thought it was because an excessive longitude of the command plus the parameters, but now I see it's because cmd.exe dislike the use of double quotes in both the command path and the parameters and then asks for single quotes for the parameters when in other contexts thislikes single quotes. What a picky! (<- I like this new word for me, it's funny B) ) I prefer the first solution, the workingdir one because I see it less proper to errors. Now I can do it throught cmd.exe and then add a variable, like this:

$command = 'NeroCmd.exe --write --drivename d --real --speed 4 --iso "Copia de Seguridad" --iso-mode2 --speedtest --enable_abort --detect_non_empty_disc --underrun_prot --create_iso_fs --verify --dvd %tmp%"\Copia de Seguridad.zip" --force_erase_disc'
$workdir = "C:\Archivos de programa\Ahead\Nero\"
RunWait(@ComSpec & " /c " & $command, $workdir)

(I stripped down the @SW_HIDE during debugging to read the output.) Thanks for your help, anyhow it seems a difficult aspect for novices, so it'll take some time to be realy clear to me and I'll keep reading the thread for further reference. And I still have more replies...

See you

Carlos Villar

Share this post


Link to post
Share on other sites

Hello /dev/null:

(Funny name :D )

Thanks :)

What a picky! (<- I like this new word for me, it's funny B) )

It should be: What a picky bastard :o:graduated:

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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