0

I want to start a command in command prompt, but os.system() can only do one command, and I want it to start from a url.
Example:

import os,getpass
print "Altline (C) James Lu"
print "All rights reserverd."
def currentuser():
    try:
        return "Users/" + getpass.getuser()
    except:
        print "Cannot detect user, starting from drive."
        return ""
try:
    os.path.isdir("C:/")
except:
    p = raw_input("C drive does not exist, please input drive:")+":/"+ currentuser()
else:
    p = "C:/" + currentuser()
while True:
    prompt = p+">"
    c = raw_input(prompt)
    if c.startswith("to"):
        u = c.lstrip("to ")
        if os.path.exists(os.path.join(p,u)):
            p = os.path.realpath(os.path.join(p,u))
        else:
            print "No such directory/file"
    elif c.startswith("goto"):
        if os.path.exists(u):
            p = os.path.realpath(u)
        else:
            print "No such directory/file"

    else:
        print os.system(c) 

Note: I am doing this because there is something crazy wrong with starting it, so you can't just start it up directly.

3
Contributors
3
Replies
81
Views
3 Years
Discussion Span
Last Post by Gribouillis
1

I'm not really clear what you're trying to do but os.system has fallen from favor and the subprocess module is recommended. Maybe that will suit your needs better.

Votes + Comments
indeed
WRONG! os.system for all the commands in command line! not for launching programs!
0

How would you phrase the command line if you had to launch the program from a terminal ? This is the command line to use for your call. Also rrashkin is right in recommending the subprocess module. I recommend my snippet to run the command in a comfortable way.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.