0

I have multiple files .py and one file .sln for my gateway in Raspberry Pi 3.

My question is how to run all of those files together?

1
  • Without a lot more details on what you are trying to achieve and where the software came from we are going to be stuck. Python files are run using Python or Python3 from the command line and a quick Google says the sln file is a visual studio project file but that's as far as I can go.
    – user115418
    Commented Jun 10, 2020 at 11:30

3 Answers 3

2

On the command line run one script after the other with a trailing &, for example:

rpi ~$ /usr/bin/python3 /full/path/to/script1.py &
rpi ~$ /usr/bin/python3 /full/path/to/script2.py &
rpi ~$ /usr/bin/python3 /full/path/to/script3.py &

This will run the scripts in the background and you get the command prompt again after starting the script, so you can start the next script. Look what's running in the background with:

rpi ~$ jobs
0

I can't write anything about running under a single py file. You can add the following commands in a script file (for example runall.sh) and run them in batches.

Example Code:

python main.py & python main.ate.py & python lcd.py & python command.py &

0

@Ingo provides a solution that should meet your needs, assuming you need to run each file as a separate and independent process. Unix as whole is built around the idea of one process being able to execute, or to be exact fork, other processes. It is incredibly neat and simple.

But if your needs are a bit more subtle, and you want to glue the processes together so one process controls another, even over a network, have a look at Don Libe's Expect, which takes shell programming into another realm eg driving vi from a script.

One other thing if you wish to execute python programs from the command line always make sure you're first line in the script is #!/bin/python, or wherever python is installed (python3 obviously if you're using python3). Again the sequence #! is built into the ethos of Unix, it's not Python specific. A shell script has a similar first line #!/bin/sh or similar.

Once you've added the line you can run the script using its name alone, so long as the directory holding the script is listed in the $PATH shell variable or you give a full path to the script such as "./script.py"

You don't have to add the #! line but it is the Unix way.

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.