Python Forum
<SOLVED>os.system needs a string in quotes
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
<SOLVED>os.system needs a string in quotes
#7
(Oct-05-2016, 08:42 AM)Ofnuts Wrote:
(Oct-04-2016, 09:02 PM)snippsat Wrote: You should also use Subprocess it replace use of older os.system().

... and use it to call you srm command directly (ie, without a intermediate shell). Then each of your command parameters is a string in a list and you completely avoid the shell syntax issues.

Hmm... that would be nice but this is what I get when srm-ing /home/fred/Git/test (folder):
Error:
/home/fred/Git/test (folder) Traceback (most recent call last):   File "/home/fred/.local/share/caja-python/extensions/caja-wipe.py", line 112, in wipe_file     subprocess.call([cmd])   File "/usr/lib/python2.7/subprocess.py", line 522, in call     return Popen(*popenargs, **kwargs).wait()   File "/usr/lib/python2.7/subprocess.py", line 710, in __init__     errread, errwrite)   File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child     raise child_exception OSError: [Errno 2] No such file or directory
Applicable code is this:
    def wipe_file(self, menu, file):
        for filename in filelist:
            path = pwd+"/"+filename
            path = str(path)
            if not os.access(path, os.W_OK):
                print("You do not have permission to wipe this file") # Debugging
                return
            # print(filelist) # Debugging
            # print(filename) # Debugging
            print(path) # Debugging
            cmd = "srm -rv "+path # -v is good for debugging
            subprocess.call([cmd])
If needed, the entire source code is on GitHub:
https://github.com/Fred-Barclay/Caja-Wipe
(Look in src/caja-wipe.py)

Thanks for all help so far!

EDIT: Python 3.4
OS: Arch
Editor: Atom with Material Syntax UI and the Termination terminal plugin

Micah 6:8
Reply


Messages In This Thread
RE: os.system needs a string in quotes - by wavic - Oct-04-2016, 08:45 PM
RE: os.system needs a string in quotes - by Ofnuts - Oct-05-2016, 08:42 AM
RE: os.system needs a string in quotes - by Fred Barclay - Oct-06-2016, 12:03 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] Open file, and insert space in string? Winfried 7 582 May-28-2025, 07:56 AM
Last Post: Winfried
Question [SOLVED] [Beautiful Soup] Replace tag.string from another file? Winfried 2 650 May-01-2025, 03:43 PM
Last Post: Winfried
  [SOLVED] Sub string not found in string ? jehoshua 4 1,615 Dec-03-2024, 09:17 PM
Last Post: jehoshua
Question [SOLVED] How to replace characters in a string? Winfried 2 1,225 Sep-04-2024, 01:41 PM
Last Post: Winfried
  Need help on how to include single quotes on data of variable string hani_hms 5 7,906 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into &lt;/&gt;? Winfried 0 2,828 Sep-03-2022, 11:21 PM
Last Post: Winfried
  [SOLVED] [BeautifulSoup] Turn select() into comma-separated string? Winfried 0 2,009 Aug-19-2022, 08:07 PM
Last Post: Winfried
  Adding string after every 3rd charater [SOLVED] AlphaInc 2 2,225 Jul-11-2022, 09:22 AM
Last Post: ibreeden
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 3,447 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  Replace String in multiple text-files [SOLVED] AlphaInc 5 11,573 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

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