Results 1 to 7 of 7

Thread: python output for shell command?

  1. #1
    Join Date
    May 2008
    Beans
    99

    python output for shell command?

    How could I make the output of a python program as a command? For example, my python program print:
    Code:
    cd /home/chris/Books/2010
    and then Ubuntu shell execute the command above. Thanks!!

  2. #2
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: python output for shell command?

    Code:
    $(command)
    See:
    Code:
    man bash | less +/"Command Substitution"

  3. #3
    Join Date
    May 2008
    Beans
    99

    Re: python output for shell command?

    Sorry, when I add the code below in my python program, it doesn't work as I thought:

    print "$ cd /home/chirs/book/2010"

    anything I did wrong?

  4. #4
    Join Date
    May 2008
    Beans
    99

    Re: python output for shell command?

    Sorry, when I add the code below in my python program, it doesn't work as I thought:

    Code:
    print "$ cd /home/chirs/book/2010"
    anything I did wrong?

  5. #5
    Join Date
    May 2008
    Beans
    99

    Re: python output for shell command?

    help please ......

  6. #6
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: python output for shell command?

    Oh, you want something like:
    Code:
    import os
    
    cmd='ls -al /home'
    os.system(cmd)
    http://docs.python.org/tutorial/stdl...stem-interface

  7. #7
    Join Date
    Oct 2010
    Beans
    71

    Re: python output for shell command?

    Quote Originally Posted by Unewbeginner View Post
    Sorry, when I add the code below in my python program, it doesn't work as I thought:

    Code:
    print "$ cd /home/chirs/book/2010"
    anything I did wrong?
    Listen to sisco311, that's what you want, but also you don't want to be using that $ symbol. The shell shows it as an indicator of your privelidge level and the kind of input it wants, it's not a part of the command.
    Angus

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •