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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

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

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

read into [php_man]exec[/php_man] and/org [php_man]shell_exec[/php_man]
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

What's this program doing? randomizing the serial number or something? PHP can do that!
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Post by hairyjim »

Cheers mate. I'll check it out.
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Post 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:
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Oh ok, so it'll probably be easier just to use it then?
hairyjim
Forum Contributor
Posts: 219
Joined: Wed Nov 13, 2002 9:04 am
Location: Warwickshire, UK

Post by hairyjim »

Yeah seriously the 'unlock tool' is much more complicated than what can be achieved via PHP.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

I dunno I've seen PHP do some pretty crazy stuff...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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...
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post 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:
Post Reply