Python Forum
setting evironment of Linux using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
setting evironment of Linux using python
#1
Hi I am trying to convert a shell script to python. In shell script they are setting the Environment I don't know how to do that using the python here is the sample from the shell script.

# set the test Environment
SAM_HOME=/opt/test
[ -f "~sam/bin/testenv" ] && SAM_HOME=~sam
. $SAM_HOME/bin/testenv
. $SAM_HOME/bin/session
Reply
#2
Hi, I don't know the exact answer to your question, but would it be fine to execute your existing shell script with Python's "os" module?
http://www.pythonforbeginners.com/os/pythons-os-module
Particularly the "os.system()" method:
https://docs.python.org/3/library/os.html#os.system
Reply
#3
hi, I am trying it in python in this way

# set the test Environment
SAM_HOME = "/opt/test"


if os.path.exists("~sam/bin/test"):
SAM_HOME = "~sam"
os.system(". " + SAM_HOME + "/bin/test")
os.system(". " + SAM_HOME + "/bin/session")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is possible to run the python command to call python script on linux? cuten222 6 633 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  A question about setting up Python JanOlvegg 1 537 Feb-20-2023, 10:21 PM
Last Post: deanhystad
  Setting up new Python kernel for JupyterLab Desktop on M1 Mac daler6 0 1,225 Jun-20-2022, 03:45 AM
Last Post: daler6
  How to use a variable in linux command in python code? ilknurg 2 1,547 Mar-14-2022, 07:21 AM
Last Post: ndc85430
  Python syntax in Linux St0rmcr0w 2 44,827 Jul-29-2021, 01:40 PM
Last Post: snippsat
  Login to NordVPN on Linux with python script AGreenPig 2 5,908 Feb-09-2021, 10:44 AM
Last Post: AGreenPig
  how to run linux command with multi pipes by python !! evilcode1 2 6,219 Jan-25-2021, 11:19 AM
Last Post: DeaD_EyE
  where to get portable Python for Linux (Fedora)? python001 5 6,158 Nov-01-2020, 05:23 PM
Last Post: Larz60+
  Python in Linux environment on RPI kendias 22 10,906 Sep-05-2020, 03:04 AM
Last Post: K_Research
  How do I pick the right python in Linux env? MDRI 9 3,587 Jun-27-2020, 05:40 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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