Python Forum
Is possible to run the python command to call python script on linux?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is possible to run the python command to call python script on linux?
#7
Safety note:

shell=True should not be used under any circumstances.

Safer:
from subprocess import Popen


Popen(["python", "your_app.py"])
Safer with the help of shlex:
import shlex
from subprocess import Popen


command = shlex.split("python your_app.py")
print(command)

Popen(command)
If you make your script executable, then add the shebang, which runs the right interpreter. e.g., you can also run Perl, PHP, Ruby and many other interpreted languages with the help of the shebang.

The shebang for bash:
#!/bin/bash
The shebang for python:
#!/usr/bin/env python3
The shebang for PHP:
#!/usr/bin/env php
Pedroski55 likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: Is possible to run the python command to call python script on linux? - by DeaD_EyE - Jan-30-2024, 09:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 479 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  ChromeDriver breaking Python script genericusername12414 1 355 Mar-14-2024, 09:39 AM
Last Post: snippsat
  using PowerShell from Python script for mounting shares tester_V 8 599 Mar-12-2024, 06:26 PM
Last Post: tester_V
  No Internet connection when running a Python script basil_555 8 716 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 594 Mar-10-2024, 07:24 PM
Last Post: Winfried
  python script is hanging while calling a procedure in database prasanthi417 4 587 Jan-17-2024, 02:33 PM
Last Post: deanhystad
  run part of a script with a different version of Python jdog 2 486 Jan-09-2024, 08:49 PM
Last Post: jdog
  How to check if Skype call is connected or disconnected in Python? boral 1 431 Dec-28-2023, 08:31 AM
Last Post: buran
  Help Running Python Script in Mac OS emojistickers 0 373 Nov-20-2023, 01:58 PM
Last Post: emojistickers
  python command interface cwc2 5 1,288 Sep-20-2023, 05:19 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020