-1

I have different maven/java projects folder in Eclipse IDE and i usually run those with "Run Configuration". These are Selenium and Cucumber based projects which have a TestRunner.java class and i run those as TestNG runners.

Now, is there any way to invoke the TestNG runner classes of all projects at once through any CMD commands, batch file or Script?

I need to start all project execution parallely using some solution, but cant find one

1
  • Any reason why you're not using a CI/CD tool? Those are made for parallel execution.
    – Lee Jensen
    Commented Oct 11 at 17:49

1 Answer 1

0

For Unix-based systems, you can use the command &:

command1 & command2 & command3 &...

If you want more control over each command, you can use xargs:

echo -e "command1\ncommand2\ncommand3" | xargs -P 3 -I {} sh -c "{}"

xargs takes input (lines of text) and passes each line as arguments to the specified command.

-P 3 specifies the number of parallel processes to run. Here, it will run up to 3 commands at the same time.

-I {} allows xargs to substitute {} with each line from the input. So each of the commands (sleep 5, sleep 10, echo Done!) will replace {} in the following command.

sh -c "{}" runs a shell (sh) command, where {} will be replaced by each of the commands from the input.

sh -c allows the shell to execute the command passed as a string argument.

If you need more flexibility, I suggest looking into GNU's parallel:

parallel ::: "command1" "command2" "command3"

In Windows/Powershell, you can use Start-Job:

$command1Job = Start-Job -ScriptBlock { command1 }
$command2Job = Start-Job -ScriptBlock { command2 }

To check the status of the jobs:

Get-Job -Id $command1Job

To get the output from a job:

Receive-Job -Id $command1Job

Also, you can use Windows Subsystem for Linux (WSL):

wsl command1 & command2 & command3 & ...

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.