Windows 7 basic scripting, usage piping, output redirections and variable in one example.

#1
Hi,

I mostly use another OS, and need to rewrite following script into one which works in windows.

OK, here's the command:
curl -s -x 127.0.0.1:8888 -b ./cookies.txt -X GET http://localhost:8080/api/attachment/list 2>&1 | tr -d '[]' | sed "s/,/\n/g" | head -n 1 | sed "s/.\(.*\)./\1/"

here's what it does: loads content of some URL using curl and redirect output 2 to std one. This return json like: '["a", "b", "c"]' this result is piped to following commands resulting to single line output:
a
Commands are little bit crazed, because tr does not work with \", i don't know why. *But* given command *works*. What I need to do, is to store its result to variable. (need to be used later).I've tried to do:
set myVariable=...
but that stores empty string into it instead of valid value.
I've found some workaround using for cycle, but that did not liked redirection of output.

Does anybody know solution(even really complicated one) to this simple problem?
 


Josephur

Windows Forum Admin
Staff member
Premium Supporter
#2
Never forget the reverse piping abilities...

echo blah blah > tmpFile
set /p myvar= < tmpFile
del tmpFile

myvar should now = "blah blah"
 


Josephur

Windows Forum Admin
Staff member
Premium Supporter
#3
You can also use a for statement...

for /f "delims=" %a in ('ver') do @set myvar=%a
echo %myvar% will return the output.. in this case for me "Microsoft Windows [Version 6.1.7601]"
 


This website is not affiliated, owned, or endorsed by Microsoft Corporation. It is a member of the Microsoft Partner Program.
Top