Results 1 to 5 of 5

Thread: EXEC: Multi-line input

  1. #1
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default EXEC: Multi-line input

    I created my very first C++ program And now I want to call it from PHP. The problem that I have is that the inputs are on different lines. I.E.:
    Code:
    program.exe
    What's your name: <name>
    What's your username: <username>
    output here
    How can I run an exec() function to fill in those inputs? I tried variations of:
    Code:
    echo exec("cd path/to/program/ && program.exe\nJas\nJas\n");
    and
    Code:
    $out = array();
    echo exec("cd path/to/program/ && program.exe\nJas\nJas\n",$out);
    print_r($out);
    But it doesn't work. Any thoughts?

    If this won't work, is there an alternate way to input those without using a flat file or putting all the vars on one line?
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    try
    PHP Code:
    $out = array();
    echo 
    exec("cd path/to/program/ && program.exe -u username -p password",$out);
    print_r($out); 
    and in c++ you will access the command line arguments. an example (will store text after -p as pass and text after -u as user):
    Code:
    int main( int argc, char *argv[] ) {
        if(argc>1) {
            int i=1;
            while ((i<argc) && (argv[i][0]=='-')) {
                string val=argv[i];
                if(val=="-u") {
                    i++;
                    string user=argv[i];
                } else if(val=="-p") {
                    i++;
                    string pass=argv[i];
                }
                i++;
            }
        }
    }
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. #3
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Thank you very much for that chunk of code

    How does the command prompt process that string? For example:
    Code:
    cd path/to/program/ && program.exe -u Jas|is|cool -p "really|really"|cool
    (I'm not shallow at all )
    Will that work as expected?
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  4. #4
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    the command prompt send the arguments to the program main, and you can choose to recieve them. if you do, it sends all the arguments in order including the program name in the array argv, along with the number of arguments in argc. the code loops through the arguments, except the first one and tries to find anything beginning with a '-' if it does it will match which delimiter it is and add the text after it to a string variable.
    Last edited by Master_script_maker; 06-18-2008 at 01:29 PM.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  5. The Following User Says Thank You to Master_script_maker For This Useful Post:

    Jas (06-18-2008)

  6. #5
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    That's not quite what I am looking for, but I'll give it a try. Thanks.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

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
  •