Page 1 of 1

Pass parameters to command line app and read output? - Poss?

Posted: Fri Jul 09, 2004 6:41 am
by hairyjim
Is it possible to pass parameters to a command line application and read the output from the command line and then display/email to the user?

Here is the reason for me asking.

I have a product registration page, and the product is free of charge after registering for an unlock code.

Now I obviously wish the user to register themselves, then at some point during the registration (likely when they submit their details) I wish to generate the unlock code based on the serial number which will be a simple auto-generated number in the db.

So this would be the process there after.

Generate Serial number - (DB).
Open command line application.
Pass serial number to app command line.
Simulate 'enter' or 'Return' key hit so app goes away and generates unlock code.
Unlock code then returned to command line.
Then I need to somehow copy unlock code to the db.

I am not sure if this is achievable but I am very willing to discuss the options that may be available and listen to any comments on perhaps how to achieve this.

Cheers
Jim

Posted: Fri Jul 09, 2004 10:34 am
by feyd
read into [php_man]exec[/php_man] and/org [php_man]shell_exec[/php_man]

Posted: Fri Jul 09, 2004 10:38 am
by magicrobotmonkey
What's this program doing? randomizing the serial number or something? PHP can do that!

Posted: Fri Jul 09, 2004 10:38 am
by hairyjim
Cheers mate. I'll check it out.

Posted: Fri Jul 09, 2004 10:40 am
by hairyjim
magicrobotmonkey wrote:What's this program doing? randomizing the serial number or something? PHP can do that!
Nah, much more complicated than that :wink:

Posted: Fri Jul 09, 2004 10:41 am
by magicrobotmonkey
Oh ok, so it'll probably be easier just to use it then?

Posted: Fri Jul 09, 2004 10:44 am
by hairyjim
Yeah seriously the 'unlock tool' is much more complicated than what can be achieved via PHP.

Posted: Fri Jul 09, 2004 10:47 am
by magicrobotmonkey
I dunno I've seen PHP do some pretty crazy stuff...

Posted: Fri Jul 09, 2004 10:49 am
by feyd
I largely doubt it's too complicated to be done in PHP, although it probably is more efficient to leave it in the compiled program. However, you may need to port it over if the host(s) you use further down the line disallow execution of programs...

Posted: Fri Jul 09, 2004 11:08 am
by xisle
execute will allow the -print output to be stored in an array..
for instance with the find command like this...

Code: Select all

<?php

$find=exec("find /usr/local -name "foo*" -print", $findresults);

?>
..just loop through the resulting array to get your program output.
yes this is only part of your question :wink: