How can I print out a variable in batch file

Microsoft Windows xp professional editio...
October 6, 2009 at 10:35:57
Specs: Windows XP

Please show me how to print out the below line in batch programming:

perl -e "sleep (rand 30)"

I tried:
set random_sec=perl -e "sleep (rand 30)"
echo %random_sec"

and it does not work.

Thanks for helping.

See More: How can I print out a variable in batch file

Report •

October 6, 2009 at 12:25:03

You need to enclose the random_sec variable with "%".

Like this:

echo %random_sec%

-- kptech

Report •

October 6, 2009 at 14:25:44
I tried
echo random_sec = %random_sec%

and its output is nothing as shown below:


Report •

October 6, 2009 at 18:40:42
No problems setting the var and echoing here, perhaps you should check the syntax you are using in the Set command..

You have a space before the = in this
echo random_sec = %random_sec%

but it's not shown on the output

Report •

Related Solutions

October 7, 2009 at 14:45:42
Here is my code:
set number_of_loop=%1
set /a counter=0

rem Number of loop must be enter:
if "%number_of_loop%"=="" (
goto error

set /a counter+=1
set random_sec=perl -e "sleep (rand 30)"
echo random_sec=%random_sec%
echo Number of loops=%counter%
if "%counter%"=="%number_of_loop%" (
goto end
) else (
goto loop

echo Need to enter number of loop
echo Usage: Script_Name number_of_loop


C:\WorkingFolderTemp>set number_of_loop=1

C:\WorkingFolderTemp>set /a counter=0

C:\WorkingFolderTemp>rem Number of loop must be enter:

C:\WorkingFolderTemp>if "1" == "" (goto error )

C:\WorkingFolderTemp>set /a counter+=1

C:\WorkingFolderTemp>set random_sec=perl -e "sleep (rand 30)"

C:\WorkingFolderTemp>echo random_sec=perl -e "sleep (rand 30)"
random_sec=perl -e "sleep (rand 30)"

C:\WorkingFolderTemp>echo Number of loops=1
Number of loops=1

Problem: cannot print out the random second

Report •

Ask Question