tag:blogger.com,1999:blog-4702950152327976706.post8154267769012883256..comments2024-03-27T19:28:01.524-07:00Comments on Just geeks: Save output of DOS command to variableBrent Vhttp://www.blogger.com/profile/15891142062380248367noreply@blogger.comBlogger35125tag:blogger.com,1999:blog-4702950152327976706.post-48923548753130245592014-07-31T15:40:19.323-07:002014-07-31T15:40:19.323-07:00the output is this:
ProcessId
8432
I am just int...the output is this:<br /><br />ProcessId<br />8432<br /><br />I am just interested in the second line.<br /><br />for /f "tokens=2" %i in<br /><br />does not work.<br />Please help<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-19986058714802463362013-06-12T00:28:52.782-07:002013-06-12T00:28:52.782-07:00Thank you! you save me a lot of time!
PD: it woul...Thank you! you save me a lot of time!<br /><br />PD: it would be nice if you can explain what the for loop is just actually doing and why the trick works :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-32750632216444335762012-12-12T11:35:18.299-07:002012-12-12T11:35:18.299-07:00The best answer to this is probably to install Cyg...The best answer to this is probably to install Cygwin and use bash or ksh.Hermhttps://www.blogger.com/profile/17919584082589414252noreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-61222610384344912562012-12-12T11:34:59.509-07:002012-12-12T11:34:59.509-07:00The best answer to this is probably to install Cyg...The best answer to this is probably to install Cygwin and use bash or ksh.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-42986648968225820022012-12-12T11:34:29.702-07:002012-12-12T11:34:29.702-07:00The best answer to this is probably to install Cyg...The best answer to this is probably to install Cygwin and use bash or ksh.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-30443665359231874642011-12-08T02:34:13.378-07:002011-12-08T02:34:13.378-07:00Thanks really helpful all of it. Carrot before pip...Thanks really helpful all of it. Carrot before pipe and all. Thanks a tonAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-5087323440807888052011-12-01T06:57:19.209-07:002011-12-01T06:57:19.209-07:00Hey, Its "Sets" the final line of the &q...Hey, Its "Sets" the final line of the "command" you execute when its of multi-line resulting command. <br /><br />eg:<br />FOR /F "tokens=1 delims=" %A in ('dir') do SET myVar=%A<br /><br />Is there a way we can resolve this?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-86847237926560558252011-07-27T08:06:56.630-07:002011-07-27T08:06:56.630-07:00Thank you! Everything I needed was in here.Thank you! Everything I needed was in here.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-57007407517340790722011-05-18T09:40:11.375-07:002011-05-18T09:40:11.375-07:00This is an old thread, but THANK YOU!!!!!!!!!!!!!!...This is an old thread, but THANK YOU!!!!!!!!!!!!!!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-57428749211339157672010-10-23T08:29:26.677-07:002010-10-23T08:29:26.677-07:00Thank you for sharing!
Excellent articleThank you for sharing!<br />Excellent articleAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-37915280495082780502010-09-16T17:45:34.442-07:002010-09-16T17:45:34.442-07:00Using a caret to escape out the pipe was handy inf...Using a caret to escape out the pipe was handy info, thankyou!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-41677941357247812232010-09-09T23:20:03.887-07:002010-09-09T23:20:03.887-07:00I was ready to use your solution altough I was sur...I was ready to use your solution altough I was sure that I've already used a simple set VAR=%ANTOTHERVAR%.<br />Then I found it and since your blog is well placed when searching for this problem, I thought I'd better post it here.<br /><br />set VAR=%CD%<br /><br />Yeah, right, anything but POSIX compatibility... but it works.<br /><br />SimonAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-42263654411018203032010-08-11T12:23:25.658-07:002010-08-11T12:23:25.658-07:00I often went crazy trying to return a shell comman...I often went crazy trying to return a shell command result in a variable (cd, date, ...)<br />You provided the cure!<br /><b>Thaks a lot!!!</b>spacemannoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-39035235220441311272010-07-02T20:36:28.844-07:002010-07-02T20:36:28.844-07:00Awesome dude, thanks for the help.Awesome dude, thanks for the help.Erichttps://www.blogger.com/profile/09730543221948552966noreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-6409398256248088762010-06-24T16:40:59.382-07:002010-06-24T16:40:59.382-07:00I am trying to run:
FOR /F "tokens=1 delims=...I am trying to run:<br /><br />FOR /F "tokens=1 delims=" %%A in ('A:\BIN\SED -f A:\IPSCR.SED A:\IP1.TXT') DO SET IPADR=%%A<br /><br />in a batch file. I get a syntax error after this runs. The output from A:\BIN\SED -f A:\IPSCR.SED A:\IP1.TXT is 1921684253, so I don't think that's what's causing the problem. <br /><br />Does anyone have any ideas?Danielnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-6077900625180374452010-06-10T12:19:54.712-07:002010-06-10T12:19:54.712-07:00I love you!
All kidding aside it did help, thank y...I love you!<br />All kidding aside it did help, thank you.Josehttps://www.blogger.com/profile/17954019296256626227noreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-17643782297069694472010-04-27T04:20:22.802-07:002010-04-27T04:20:22.802-07:00Very useful, thanks a lot!Very useful, thanks a lot!markhttp://free-quiz-tips.comnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-45274371812430000192010-01-12T02:21:43.262-07:002010-01-12T02:21:43.262-07:00When you use a pipe you need to prefix it with a c...When you use a pipe you need to prefix it with a caret ^.<br /><br />.. %%i in (`wget -q -O- %FEED% ^| sed -n -f rss.sed`) do ..<br /><br />but unlike BASH it seems that you can't store multiline variables and are forced to use temp files.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-39768377788970842922009-11-27T12:51:50.942-07:002009-11-27T12:51:50.942-07:00FOR /F "tokens=1 delims=" %%A in ('p...<em>FOR /F "tokens=1 delims=" %%A in ('ping -n 1 www.google.com | find "Reply"') do SET PING=%%A</em><br /><br>gives me that error message: <br><br><em>| was unexpected at this time.</em>Veskonoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-60956395818807610022009-11-10T15:51:00.102-07:002009-11-10T15:51:00.102-07:00Hi anonymous,
I'm not sure what you mean. If ...Hi anonymous,<br /><br />I'm not sure what you mean. If I do something that has a space in the output of the command I think it works fine for me, but maybe you can clarify your problem.<br /><br />Here is what I tried. <br /><br />FOR /F "tokens=1 delims=" %A in ('date /t') do SET myVar=%A <br /><br />echo %myVar%<br /><br />In my case, I got Tue 11/10/2009 as the output<br /><br />I hope this is helpful.<br /><br />BrentBrent Vhttps://www.blogger.com/profile/15891142062380248367noreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-18797660745929999762009-11-06T13:57:38.561-07:002009-11-06T13:57:38.561-07:00I noticed that if the out has a space in it, it on...I noticed that if the out has a space in it, it only returns everything before the space. Why is this?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-30530211540313533382009-10-26T08:31:08.836-07:002009-10-26T08:31:08.836-07:00Anonymous,
Agreed, this is definitely a lame solu...Anonymous,<br /><br />Agreed, this is definitely a lame solution, but the only one I know of. I was shocked how difficult and feature lacking dos really is. <br /><br />Thank you for the feedback.<br /><br />Cheers,<br /><br />BrentBrent Vhttps://www.blogger.com/profile/15891142062380248367noreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-4301419551764700132009-10-25T07:21:22.298-07:002009-10-25T07:21:22.298-07:00Excellent description (it was good to hear that th...Excellent description (it was good to hear that this really is a hard thing to do in DOS), good solution, and great description of solution (lame but very effective!). Many thanks!!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-61073038109294352372009-09-18T10:12:10.659-07:002009-09-18T10:12:10.659-07:00Anonymous,
That would me nice. :)
BrentAnonymous,<br /><br />That would me nice. :)<br /><br />BrentBrent Vhttps://www.blogger.com/profile/15891142062380248367noreply@blogger.comtag:blogger.com,1999:blog-4702950152327976706.post-38372415297035588272009-09-17T11:00:24.736-07:002009-09-17T11:00:24.736-07:00Thanks, very cool.
Now what if your command was a...Thanks, very cool.<br /><br />Now what if your command was a piped command (multi command solution)?<br /><br />i.e. systeminfo | find /I "system up time"<br /><br />Thanks again...Anonymousnoreply@blogger.com