ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.