Comments on: Microsoft Backticks Comments on Ask MetaFilter post Microsoft Backticks Fri, 23 Sep 2005 05:45:33 -0800 Fri, 23 Sep 2005 05:45:33 -0800 en-us 60 Question: Microsoft Backticks How do I get the ouput of a windows console program / script into a batch file variable? <br /><br /> Unix user here, trying to translate a shell script into a batch file that will run in a Windows command shell environment. I need to get the output of a program or script into a variable. <br> <br> In a Unix shell it is easy : var=`program`, but I have not been able to figure out how to do the same in a batch file.,2005:site.24448 Thu, 22 Sep 2005 23:49:56 -0800 Deepspace dos batch By: rolypolyman Windows batch files kind of suck, but I think you may be able to output the program to a file with the &gt;&gt; [filename] operator, then bring it back into the script with &lt;&lt; [filename], or use that to self-write a batch file that is then called. It's not really an answer but is one area where I'd look.,2005:site.24448-388147 Fri, 23 Sep 2005 05:45:33 -0800 rolypolyman By: grouse You might consider just shipping your script with a Windows version of bash. It'll make your life a lot easier.,2005:site.24448-388181 Fri, 23 Sep 2005 07:02:50 -0800 grouse By: curtm Sad to say, but Windows batch language is not much enhanced from its roots in MS-DOS, when it was an operating system that fit on a 360 kb floppy.<br> <br> If you want to do anything substantial, you'll have to use an external <a href="">scripting language</a> or command shell. The above suggestion about using a windows implementation of the BASH shell is a good one. If you don't want Microsoft to be dissapointed with you, you can use <a href="">Windows Scripting Host</a>.,2005:site.24448-388197 Fri, 23 Sep 2005 07:21:09 -0800 curtm By: theora55 from a command prompt "ping &gt; c:\ping.txt" works. It does not work from the Run box. You want to specify the directory path to the save location. I haven't taken the time to figure out how Windows selects what directory is current, but it's certainly not always the one I would expect.,2005:site.24448-388206 Fri, 23 Sep 2005 07:26:56 -0800 theora55 By: soundslikeobiwan You can probably do this in an XP batch file. Read the help for the "for" statement,<br> <pre><br> for /?<br> </pre><br> The example there is:<br> <pre><br> FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i<br> </pre><br> Which prints the environment variable names without their values. You can fool with the delimiters to get different token parsing.<br> <br> There is a whole bunch of useful information hidden in help strings from the various CMD.EXE builtins, like<br> <pre><br> set /?<br> if /?<br> call /?<br> </pre><br> <br> You'll have to think differently than bash, but it's pretty powerful.,2005:site.24448-388242 Fri, 23 Sep 2005 08:26:04 -0800 soundslikeobiwan By: stovenator The trick used by many people is setting an environment variable, and then using that. There is just no other variable available to use in a batch file.<br> <br> Here's an example from a batch file I have on a Win2000 machine to get the date.<br> -------------------------------------------------------------<br> <br> @echo off<br> SET %%PATH = "c:\winnt\system32\"<br> <br> <br> For /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (<br> For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (<br> set dow=%%i<br> set %%a=%%j<br> set %%b=%%k<br> set %%c=%%l<br> set hh=%%m<br> set min=%%n<br> set ss=%%o<br> )<br> )<br> <br> SET YY=%YY:~2,2%<br> <br> <br> REM Let's see the result.<br> For %%i in (dow dd mm yy hh min ss) do set %%i,2005:site.24448-388487 Fri, 23 Sep 2005 15:02:00 -0800 stovenator