Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6376891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:48:06+00:00 2026-05-25T01:48:06+00:00

Language: Python v2.6.2 OS: AIX 5.3 I’m using Python to restore some files from

  • 0

Language: Python v2.6.2

OS: AIX 5.3

I’m using Python to restore some files from a backup to a test system – all commands are called in the manner below, however some just plain don’t want to work.

#!/usr/bin/python
import subprocess, shlex

cmd = 'sudo rm -rf /work/TEST/*'
arg = shlex.split(cmd)

# This does not work
p = subprocess.Popen(arg)

# This, however, works just fine
p = subprocess.Popen(cmd, shell=True)

If I remove the *’s from the commands they work fine (well, they work as they should without the wildcards, which is unfortauntely not what I want).

I really do not want to use shell=True for obvious security reasons, however there are a couple of other commands that basically do the same thing. If there is a wildcard in the command it just won’t work – it executes without error, just doesn’t do anything.

Interestingly the following command (parsed through shlex):

sudo mv /work/testrestore/production/* /work/TESTC

Produces the following:

mv: 0653-401 Cannot rename /work/testrestore/production/* to /work/TESTC/*: A file or directory in the path name does not exist.

It’s as if unix is now trying to move a file named * rather then using * as a wildcard. Is this typical behaviour of shlex?

Edit: I have tried escaping the * with a \, also tried changing from single quotes to double.. not that I expected that to do anything.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:48:07+00:00Added an answer on May 25, 2026 at 1:48 am

    For replacing the * with what it means, you either need the shell or you need the glob module. So the easiest way would be shell=True (if the command is constant, I do not see any security holes).

    Another approach would be

    #!/usr/bin/python
    import subprocess
    import shlex
    import glob
    
    cmd = 'sudo rm -rf /work/TEST/*'
    arg = shlex.split(cmd)
    arg = arg[:-1] + glob.glob(arg[-1])
    
    # This should work now
    p = subprocess.Popen(arg)
    

    or, if you would nevertheless append the path by yourself,

    cmd = 'sudo rm -rf'
    basearg = shlex.split(cmd)
    arg = basearg + glob.glob(path+"/*")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm translating some stuff from MATLAB to the Python language. There's this command, unique(a),
I've been an avid learner of the Python language for quite some time. Having
I've been using the following memoizing decorator (from the great book Python Algorithms: Mastering
My primary language is Python. Often when I need to do some cpu heavy
I like programming in the Python language to solve daily problems in system administration
I like programming in the Python language to solve daily problems in system administration
I'm using google-app-engine in python language, I'm want to do something when user logon
I'm writing what might not even be called a language in python. I currently
Since Python is a dynamic, interpreted language you don't have to compile your code
Which language for quick GUI app + sqlite database CRUD (2-4 tables). Java, Python?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.