-1

I have two python scripts and I have to run them parallelly at the same time and store their retun value in a variable. Could you please help me how to do this?

Example:

script1.py and script2.py

x is variable to store script1.py return value

y is variable to store script2.py return value

both the scripts are returning either 0/1.

Toto
  • 89,455
  • 62
  • 89
  • 125
Shivika Patel
  • 213
  • 1
  • 5
  • 14

1 Answers1

0

You can run the process on the background using & operator. Then you have to wait for all the background processes using wait. This command also provides return code of the awaited process.

Quick and dirty example:

#!/bin/bash

# first command to be executed
sleep 3 &
pid1=$!

# second command to be executed
sleep 5 &
pid2=$!

wait $pid1
x=$?

wait $pid2
y=$?

echo "x: $x, y: $y"
rcwnd_cz
  • 909
  • 6
  • 18