LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2009, 03:10 PM   #1
PB0711
Member
 
Registered: Aug 2004
Location: London, UK
Distribution: Ubuntu 10.10, ubuntu 11.04, suse 9.2, OSX
Posts: 259

Rep: Reputation: 30
web-interface to command line program? possible?


Hello,

I have a program that works in the command line. I would like to use a web interface to allow users easier access to the program. My thought is to have some forms that they fill out and then click submit. This takes them to the next page that reads STOUT and puts the text onto the webpage as it appears. Then at the end another form appears and the user fills that out to go to the next step.
Can I do something like this in php? I have some code (from someone else) but its not really running so I'm probably doing something not possible or something stupid.
Code:
$descriptorspec = array(
    0 => array("pipe", "r"), 
    1 => array("pipe", "w"), 
    2 => array("pipe", "w"));
   
$process = proc_open($GLOBALS['R_BIN'], $descriptorspec, $pipes);

fwrite($pipes[0], "histI<-hist(islands, plot=FALSE)\n");
fwrite($pipes[0], "save(xs, file=\"histI.RData\")" . "\n");

$r_out = "";
while (!feof($pipes[1])) {
    //$r_out .= fgets($pipes[1], 1024);
//    $r_out=fgets($pipes[0], 1024);
    $r_out =fgets($pipes[1], 1024);
    echo "$r_out\n ";
}

fclose($pipes[0]);
//print("R out ->$r_out\n");
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
 
Old 04-25-2009, 07:11 PM   #2
headrift
Member
 
Registered: Sep 2005
Distribution: Gentoo, Sabayon, Puppy, Arch
Posts: 165

Rep: Reputation: 29
It's a giant gaping security hole (as in I used it to break into my own little server once), but you could put the whole console to the web page using AJAX. XHTML form posts to php, php calls the system() command on the submitted input, prompt and returns are send back to the page, GOTO 10, rinse, repeat.

In your case, a slight modification where the program you're working on is prepended to the postdata might work. I really think your example code is way more complicated than is needed.
 
Old 04-26-2009, 10:34 AM   #3
delite
Member
 
Registered: Nov 2008
Posts: 50

Rep: Reputation: 15
When I did a little something like this (the obvious let's use traceroute), I had to add the scripts to my sudo file for it to have permission. Not that I really think this is an issue in your script but it could be of help either way.
 
Old 04-27-2009, 10:52 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
A CGI wrapper that extracts values from a form and passes them as appropriate arguments to your standalone commandline script is fairly common practice. You can pass data to the child process using pipes, as your original example has shown, however I tend to use files as temporary stores for passing data around (not suggesting your method is either more or less preferred).
--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command Line Interface sj061 Linux - Newbie 4 02-22-2007 01:48 AM
Replace Command Line Interface sekelsenmat Mandriva 3 11-01-2006 09:20 AM
Can only use command line interface! The helpless one Linux - Newbie 6 03-12-2006 03:42 PM
Command line through a web interface tangle Linux - Software 2 01-13-2005 02:54 PM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 08:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration