when we run a command like below we get output on windows machine.
cmd /c "for /f "tokens=2" %a in ('echo Paris London') do echo %a"
here we have double quotes inside double quotes. windows accept this. but on nsh or Unix flaour machines this will be treated in different. this will be split into the following
%a in ('echo Paris London') do echo %a
when a same part are rejoined we will get the following
cmd /c for /f tokens=2 %a in ('echo Paris London') do echo %a
if we ran the same on windows box we get error:
2 was unexpected at this time.
if escape double quotes we should get proper result.
from agent logs i am ble to see proper command is fired but getting incorrect result.
this can be nsh issue.
workaround: a small script can be written
echo "for /f \"tokens=2\" %a in ('echo Paris London') do echo %a" > "//XYZ/PATH/test.bat"
nexec XYZ cmd /cPATH/test.bat
why not run the for loop in nsh ?
for i in Paris London
My real aim is to run a command on a Windows machine in order to collect the result in an Extended Object. So my first step is to run this command through nexec. So the echo Paris London is only an example to know how can be run a for loop using nexec in order to extract the 4th field.
% nexec -i XYZ cmd /c "for /f "tokens=4" %a in ('c:\BLACL1\NSH\bin\version.exe ^| findstr Shell') do echo NETWORK_SHELL=%a" 4 was unexpected at this time.
1 of 1 people found this helpful
it's going to be diffcult to pass in the command you want due to the double quotes and how nsh handles them vs cmd. it would be eaiser to do your loop in nsh and make a call to nexec only when you need to actually run something on the target. or you could echo your cmd bit into a batch file and run that.
i find the loops and other structures in nsh/shell much easier to work w/ than cmd.