Python Forum
moving from os to subprocess
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
moving from os to subprocess
#9
Well, in Linux if a command exit code is 0 it means that it ran without any errors. 
So that is returned by subprocess.call and subprocess.run().teturncode.

Mounting a usb stick so all users can access it is simple enough.
Create a new group and add all users to it
Make a directory at /home/ - /home/storage for example.
Give the right permissions so that group can access /home/storage.
In /etc/fstab add this line:

/dev/sdb1   /home/storage    auto    noauto,user,umask=0000   0   0

Or you can manage this using udev: https://wiki.archlinux.org/index.php/udev
I can't say more about all of this because I am the only user of the OS and never faced that need.

About using os.system to run shell commands. If you can do the same with Python do it that way.
Do users have control over which shell they can use? I prefer using zsh or fish instead of bash. The script will be useless if one shell syntax differs from another. And that is right. If you want to do something within a Python script search the net how to do it with Python, not shell commands.

Also, you may find this interesting to read: http://www.sharats.me/posts/the-ever-use...ss-module/

But as I said do not use shell commands from Python script if you can do it with Python. Consider this. It's just an example.
Let say you want to list a directory and do not know how to do it in Python.

import os

dir_ = input("Directory to be listed?\n> ") # asking the user for input. Edited: dir is a keyword
path = os.path.abspath(dir)
command = 'ls -a' + path
os.system(command)
Everything looks normal, right?
What if the user input is something like this: . ; rm -rf /home/$USER/? It will list the current working directory and then the home will be wiped out. The same is applicable for subprocess if you are using shell=True parameter.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
moving from os to subprocess - by Barrowman - Dec-17-2017, 04:11 PM
RE: moving from os to subprocess - by wavic - Dec-17-2017, 05:59 PM
RE: moving from os to subprocess - by Barrowman - Dec-17-2017, 06:19 PM
RE: moving from os to subprocess - by Barrowman - Dec-17-2017, 07:59 PM
RE: moving from os to subprocess - by wavic - Dec-17-2017, 10:35 PM
RE: moving from os to subprocess - by Barrowman - Dec-17-2017, 11:02 PM
RE: moving from os to subprocess - by wavic - Dec-17-2017, 11:28 PM
RE: moving from os to subprocess - by Barrowman - Dec-18-2017, 09:04 AM
RE: moving from os to subprocess - by wavic - Dec-19-2017, 10:20 PM
RE: moving from os to subprocess - by ezdev - Dec-20-2017, 01:02 AM
RE: moving from os to subprocess - by Barrowman - Dec-20-2017, 09:08 AM

Forum Jump:

User Panel Messages

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