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

  • SEARCH
  • Home
  • 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 9229259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:31:39+00:00 2026-06-18T05:31:39+00:00

I can not get the subprocess.call() to work properly: >>> from subprocess import call

  • 0

I can not get the subprocess.call() to work properly:

>>> from subprocess import call
>>> call(['adduser', '--home=/var/www/myusername/', '--gecos', 'GECOS', '--disabled-login', 'myusername'], shell=True)
adduser: Only one or two names allowed.
1

But without shell=True:

>>> call(['adduser', '--home=/var/www/myusername/', '--gecos', 'GECOS', '--disabled-login', 'myusername'])
Adding user `myusername' ...
Adding new group `myusername' (1001) ...
Adding new user `myusername' (1001) with group `myusername' ...
Creating home directory `/var/www/myusername/' ...
Copying files from `/etc/skel' ...
0

Or the same directly in shell:

root@www1:~# adduser --home=/var/www/myusername/ --gecos GECOS --disabled-login myusername
Adding user `myusername' ...
Adding new group `myusername' (1001) ...
Adding new user `myusername' (1001) with group `myusername' ...
Creating home directory `/var/www/myusername/' ...
Copying files from `/etc/skel' ...

I miss some logic in the shell=True behavior. Can somebody explain me why? What is wrong with the first example? From the adduser command error message it seems that arguments are somehow crippled.

Thanks!

  • 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-06-18T05:31:40+00:00Added an answer on June 18, 2026 at 5:31 am

    When you specify shell=True you switch to quite different behaviour. From the docs:

    On Unix with shell=True, the shell defaults to /bin/sh. If args is a
    string, the string specifies the command to execute through the shell.
    This means that the string must be formatted exactly as it would be
    when typed at the shell prompt. This includes, for example, quoting or
    backslash escaping filenames with spaces in them. If args is a
    sequence, the first item specifies the command string, and any
    additional items will be treated as additional arguments to the shell
    itself. That is to say, Popen does the equivalent of:

    Popen([‘/bin/sh’, ‘-c’, args[0], args[1], …])

    So you are running the equivalent of

    /bin/sh -c "adduser" --home=/var/www/myusername/ --gecos GECOS --disabled-login myusername
    

    The error message you are getting is what happens when you try and run adduser without any arguments as all the arguments are being passed to sh.

    If you want to set shell=True then you would need to call it like this:

    call('adduser --home=/var/www/myusername/ --gecos GECOS --disabled-login myusername', shell=True)
    

    OR like this:

    call(['adduser --home=/var/www/myusername/ --gecos GECOS --disabled-login myusername'], shell=True)
    

    But mostly you just want to use call without the shell=True and use a list of arguments. As per your second, working, example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can not get logs from some customers, can I use Google Urchin in
In silverlight, I can not get INotifyPropertyChanged to work like I want it to
I can not get to make this comparison in this simple code error ..
I can not get environment at custom target shell. CMakeList.txt set( ENV{TEST_VAR} Hello )
I simply can not get Visual Studio 2005 to find the System.Configuration.ConfigurationManager class. Here
I suppose this is not so hard but I can not get it. For
I have a long label that spans multiple lines and I can not get
For the life of me, I can not get matplotlib to display graphs in
i use this method before 1 time. but Now i can not get video
I Have been fiddling with this for hours. I can not get my text

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.