6

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.

1 Answer 1

11

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%
Sign up to request clarification or add additional context in comments.

1 Comment

It nearly worked! I had to change the %I for %%I in both occurrences and it worked! The difference seems to be in if you want to execute it directly in the console or in a batch script. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.