1.

Solve : Command inside for loop in a batch file is not working?

Answer» <html><body><p>Hi All,<br/><br/>Can anyone shed any light why the follwoing line would work on machine but not on another:<br/><br/>for /f "tokens=2 delims=: " %%i in ('dir .') do set _OS_BUILDNUMBER=%%i<br/><br/>I get this error while execuing this from a file containing only this line:<br/><br/>C:\Users\User1&gt;temp.cmd<br/><br/>C:\Users\User1&gt;for /F "tokens=2 delims=: " %i in ('dir') do set _OS_BUILDNUMBER=%i<br/>'dir' is not recognized as an internal or external command,<br/>operable program or batch file.<br/><br/>But it works <a href="https://interviewquestions.tuteehub.com/tag/fine-248571" style="font-weight:bold;" target="_blank" title="Click to know more about FINE">FINE</a> in another machine with same OS version.<br/><br/>Thanks. Any help is aprreciated.<br/><br/>PS.<br/><br/>This is just an example. Practical applicability of the line is not expressed here.<br/><br/>I see you posted this on MSDN scripting forums 20 hours ago... I guess we should be flattered... you even <a href="https://interviewquestions.tuteehub.com/tag/misspelled-2836463" style="font-weight:bold;" target="_blank" title="Click to know more about MISSPELLED">MISSPELLED</a> "<a href="https://interviewquestions.tuteehub.com/tag/appreciated-2438458" style="font-weight:bold;" target="_blank" title="Click to know more about APPRECIATED">APPRECIATED</a>" identically... You haven't said what OS and service pack version you are <a href="https://interviewquestions.tuteehub.com/tag/using-1441597" style="font-weight:bold;" target="_blank" title="Click to know more about USING">USING</a> on each machine. I wonder if %comspec% is altered on the machine where dir does not work, if command extensions are enabled, and if cmd.exe has been damaged. Is one of the OSs Server 2003? Do other internal commands fail in a similar way?<br/><br/><br/><br/> Great! ComSpec was <a href="https://interviewquestions.tuteehub.com/tag/indeed-2126620" style="font-weight:bold;" target="_blank" title="Click to know more about INDEED">INDEED</a> the issue. It's fixed now. Thanks.<br/><br/>Yay! CH 1 MSDN 0<br/></p></body></html>


Discussion

No Comment Found