I would like to run selenium server from bat file. It means start hub and two nodes under the hub. On Ubuntu I have this script to do that:
java -jar $jarFilePath -role hub &
java -jar $jarFilePath -role node -hub http://173.249.58.30:4444/grid/register/ &
java -jar $jarFilePath -role node -hub http://173.249.58.30:4444/grid/register/ &
exit 0
It is necessary to chain it with & cause the first command is still running and does not run next commands. But on Windows this does not work for some reasons. I found something like this for Win but still no success. It opens three terminal but nodes are not able to register to hub:
start cmd.exe /k "cd c:\Program Files\Selenium\Server & java -jar selenium-server-standalone-3.141.59.jar -role hub"
start cmd.exe /k "cd c:\Program Files\Selenium\Server & java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://192.168.137.1:4444/grid/register/"
start cmd.exe /k "cd c:\Program Files\Selenium\Server & java -jar selenium-server-standalone-3.141.59.jar -role node -hub http://192.168.137.1:4444/grid/register/"
Thanks for any help.

The reason your commands are failing is because paths with spaces must be quoted (space is a token delimiter).
But the following will still fail because quotes cannot be nested, so the
&is not quoted and the initial batch parser treats the line as two concatenated commands instead of a singlestartcommand.For example, looking at the first line, this will not work
To fix the above, many people would escape the
&But I prefer to escape the outermost quotes so that I can write the commands as I would type them myself into the command prompt
Note that
cddoes not change your active drive by default. So say your active drive isD:, then the above will still not work. You would have to use eithercd /d "c:\Program Files\Selenium\Server", or elsepushd "c:\Program Files\Selenium\Server".But it is probably simpler to
cd /dorpushdbefore yourstartcommands so that you only have to do it once.STARTed processes inherit the environment of the parent.There is no need for the sub-process to remain open after the service terminates, so better to use
cmd /cinstead ofcmd /k.Your full script could be
But I'm not sure you actually need to explicitly run
javawithincmd.exe. You may be able to simply use the followingFinally, you likely don't need a separate window for each process, in which case you can add the
/Boption to theSTARTcommand. Put that immediately afterstart.