It's all about the answers!

Ask a question

Trying to assign the output of command to variable.Unexpe


Veena Balakrishna (361106) | asked May 03 '10, 5:57 a.m.
Hi,

I am running come commands on windows machine.
I need to assign the value of "ls|tail -1|cut -d "_" f1" to a variable,

Way of doing this on DOS prompt is
D:\DailyBuilds\esd_temp>for /F %x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%x
D:\DailyBuilds\esd_temp>echo %a%
Quebec

But the same when I put into Build Forge command , its not working
cd D:\DailyBuilds\esd_temp
.tset env "a=temp"
for /F %x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%x
echo %a%


Output

499 05/03/10 03:16PM EXEC Performing variable expansion on command line
500 05/03/10 03:16PM SCRIPT for /F %x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%x
501 05/03/10 03:16PM SCRIPT echo temp
502 05/03/10 03:16PM EXEC start
503 05/03/10 03:16PM EXEC The syntax of the command is incorrect.


Please let me know how can I get this executed on BF command.

4 answers



permanent link
Peter Birk (501145) | answered May 03 '10, 4:08 p.m.
JAZZ DEVELOPER
Hi,

I am running come commands on windows machine.
I need to assign the value of "ls|tail -1|cut -d "_" f1" to a variable,

Way of doing this on DOS prompt is
D:\DailyBuilds\esd_temp>for /F %x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%x
D:\DailyBuilds\esd_temp>echo %a%
Quebec

But the same when I put into Build Forge command , its not working
cd D:\DailyBuilds\esd_temp
.tset env "a=temp"
for /F %x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%x
echo %a%


Output

499 05/03/10 03:16PM EXEC Performing variable expansion on command line
500 05/03/10 03:16PM SCRIPT for /F %x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%x
501 05/03/10 03:16PM SCRIPT echo temp
502 05/03/10 03:16PM EXEC start
503 05/03/10 03:16PM EXEC The syntax of the command is incorrect.


Please let me know how can I get this executed on BF command.


Try putting a % in front of each %.

e.g.,
for /F %%x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%%x

Regards,
Pete

permanent link
Veena Balakrishna (361106) | answered May 04 '10, 2:51 a.m.
Hi,

I am running come commands on windows machine.
I need to assign the value of "ls|tail -1|cut -d "_" f1" to a variable,

Way of doing this on DOS prompt is
D:\DailyBuilds\esd_temp>for /F %x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%x
D:\DailyBuilds\esd_temp>echo %a%
Quebec

But the same when I put into Build Forge command , its not working
cd D:\DailyBuilds\esd_temp
.tset env "a=temp"
for /F %x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%x
echo %a%


Output

499 05/03/10 03:16PM EXEC Performing variable expansion on command line
500 05/03/10 03:16PM SCRIPT for /F %x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%x
501 05/03/10 03:16PM SCRIPT echo temp
502 05/03/10 03:16PM EXEC start
503 05/03/10 03:16PM EXEC The syntax of the command is incorrect.


Please let me know how can I get this executed on BF command.


Try putting a % in front of each %.

e.g.,
for /F %%x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%%x

Regards,
Pete

Thanks for your reply.
I tried the fix what was suggested, but I it was not executed as excepted

499 05/04/10 12:12PM EXEC Performing variable expansion on command line
500 05/04/10 12:12PM SCRIPT for /F %%x in ('"ls|tail -1|cut -d "_" -f1"') do set a=%%x
501 05/04/10 12:12PM SCRIPT echo temp
502 05/04/10 12:12PM EXEC start
503 05/04/10 12:12PM EXEC temp

"a" value still shows the value which was assigned temporarily.

Please let me know how can i go about.

Thanks
Veena

permanent link
Brent Ulbricht (2.5k11) | answered May 04 '10, 8:52 a.m.
JAZZ DEVELOPER
Hi,

I don't know your project, but I'll offer some alternative solutions. Is it possible that a batch/command file could be left on the computer with the "for..." command in it. Then the Build Forge step could just execute the script that is already on the computer.

If you can't guarantee that the script is around on the computer, another option might be to check out the script from source control in a step and then execute in the next step.

Another option that I have used in projects is to add the statements to a Build Forge register, use the Build Forge .pop dot command to write the contents of the register to the computer, and then execute the file written to disk by .pop.

bju

permanent link
Jeffrey Gordon (961310) | answered Mar 31 '11, 3:28 p.m.
You might also try using \| instead of plain | each place you use it.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.