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 9215097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:07:32+00:00 2026-06-18T02:07:32+00:00

I often wish to perform Unix commands from inside Python, but I have found

  • 0

I often wish to perform Unix commands from inside Python, but I have found recently that some commands are not found. An example is the ‘limit’ command:

$ echo $SHELL
/bin/tcsh
$ limit vmemoryuse 1000m
$ python
Python 2.7.3 (default, Aug  3 2012, 20:09:51) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system("echo $SHELL")
/bin/tcsh
0
>>> os.system("limit vmemoryuse 1000m")
sh: limit: command not found
32512
>>>

Another example is the ‘setenv’ command. Why do these commands do not work inside Python? I have tried using both the ‘os’ and ‘subprocess’ modules without success. Does anybody know of another module or method that will allow me to successfully call these commands from inside Python?

  • 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-18T02:07:33+00:00Added an answer on June 18, 2026 at 2:07 am

    That’s because some shell commands are not really programs, but internal shell commands.

    The classical example is cd: if it were an external program it would change the current directory of the new process, not the one of the shell, so it cannot be an external program.

    Roughly speaking there are two types of internal shell commands:

    1. Commands that are implemented by the shell of efficiency’s sake, but it still exists as an standalone program: true, false, test, sleep…
    2. Commands that change the environment of the shell, and so cannot be done from a child process: cd, umask, setenv, ulimit…

    The commands in the first category are quite shell specific. The commands in the second category, not so much.

    For details see the man page of the relevant shell (man bash for example).

    And if you want to know about an specific command run:

    $ type -a <command>
    

    Type is a bashism, I don’t know the equivalent in tcsh, but which is an external program, so this:

    $ which -a <command>
    

    will show you whether your command exists as an external program, but it knows nothing about shell internals.

    If you need the functionality of an internal command (of type 2 above) in your Python program you need to use the relevant system call. Hopefully it will already be available in some module. If not, you would need to write your own wrapper in C.

    About your specific commands:

    • The environment (setenv and getenv) can be manipulated with os.environ or os.getenv, os.putenv, etc.
    • For the process limits (limit) take a look at the resource module.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Often, when searching for answers, I have found that certain websites will allow you
I'm pulling some text passages from a database that have some minimal formatting using
Not sure if it's a best practice, but we wish to have a menu
I often wish to search for variables that are simply called 'c' or 'count'.
Often when writing PHP I'll have it output some HTML like this - echo
Often we have to use some of the methods which don't return anything useful.
I often wish to see the internal representation of Mathematica 's graphical objects not
It is often a pattern that I wish to poll a file for changes
I often find myself with an Option[T] for some type T and wish to
I often have data that is grouped by one or more variables, with several

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.