#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    42
    Rep Power
    2

    About exec and sys.argv[]


    Hi, I'm trying to pass the parameter from PHP to Python script. I've found some example, they used sys.argv[]. It works fine but my question is how can display every line in my python script? because we actually do execute in only one line.

    Here's the code:

    PHP Code:
    <?php 

    $name 
    'MynE';
    $age '23';
    $tmp exec("python HelloPython.py $name $age");
    print_r($tmp);

    ?>
    Python code:

    Code:
    import sys
    
    name = raw_input("Enter name here:  "+ sys.argv[1])
    age = raw_input("Enter age here:  "+ sys.argv[2])
    
    print "Hello  "+name + "You are  " +age
    The result is got is only "Enter name here: MynE" which is the first line of my python code. So how can I display the next line?

    It should be
    "Enter name here: MynE"
    "Enter age here: 23"
    "Hello MynE You are 23"

    Your answer would be very much appreciated.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,141
    Rep Power
    9398
    You're using raw_input(). It's trying to read from the keyboard, but it can't do that so it will just sit and wait.

    Don't use raw_input(). Display the prompt and assign the variable.

IMN logo majestic logo threadwatch logo seochat tools logo