Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows batch curl to variable

My knowledge of Batch scripting in Windows is poor and I need some help.

I'm trying to create a dynamic script for starting a selenium server from different EC2 instances.

What I want to do is automatically run the following script when starting the server:

cd C:\curl-7.47.1-win64-mingw\bin
%comspec% /c curl http://ipecho.net/plain > %HOMEPATH%\desktop\MyIP.txt
set /P IP= <  %HOMEPATH%\desktop\MyIP.txt
cd C:\Selenium\
java -jar selenium-server-standalone-2.52.0.jar -role node -host %IP% -hub http://*******************/grid/register --nodeTimeout 
1200 maxSession 4 -browser browserName=chrome,maxInstances=4,platform=WINDOWS, -Dwebdriver.chrome.driver=chromedriver.exe -
browser browserName=firefox,maxInstances=4,platform=WINDOWS

It works when I'm logged in the server by RDP. But when it's launched automatically by EC2, the %IP% variable is empty. I don't know what is happening. Maybe I need to be logged?

Now I'm trying another options and I decided not to use the "MyIP.txt" file and directly pass the curl to a variable and use it in the selenium command. But I don't know how to exactly do it...

Somthing like...

cd C:\curl-7.47.1-win64-mingw\bin
SET IP=curl http://ipecho.net/plain
cd C:\Selenium\
java -jar selenium-server-standalone-2.52.0.jar -role node -host %IP% -hub http://********************/grid/register --nodeTimeout 
1200 maxSession 4 -browser browserName=chrome,maxInstances=4,platform=WINDOWS, -Dwebdriver.chrome.driver=chromedriver.exe -
browser browserName=firefox,maxInstances=4,platform=WINDOWS

This, doesn't work.

Can you help me? Thank you.

like image 911
XorX Avatar asked Feb 07 '23 15:02

XorX


1 Answers

Try this if directly using in console:

for /F %I in ('curl http://ipecho.net/plain') do set ip=%I
echo %ip%

or you can Try this if writing a batch script (.bat):

for /F %%I in ('curl http://ipecho.net/plain') do set ip=%%I
    echo %ip%
like image 186
Adi Levin Avatar answered Feb 11 '23 21:02

Adi Levin