Results 1 to 8 of 8
What would be the best way to kill or start a process from a web site? Additionally, how could I get the output from the process and display it on ...
- 02-11-2010 #1Just Joined!
- Join Date
- Feb 2010
- Posts
- 3
Control a process from a web site
What would be the best way to kill or start a process from a web site? Additionally, how could I get the output from the process and display it on the site?
Thanks
- 02-11-2010 #2
you should use PHP
php run shell command - Google Searchlinux user # 503963
- 02-12-2010 #3Just Joined!
- Join Date
- Feb 2010
- Posts
- 3
Thanks for the response but I guess what I was really asking was how do I get the output of a process and display it on the screen, I know PHP but I don't know the linux commands...
If a process is already running, how can I capture it's output?
Thanks again
- 02-12-2010 #4
ok say you are running subversion, and want to verify a repo. you would do something like:
You can output that to a file.Code:svnadmin verify repo1
Now bring in PHPCode:2&>output.txt
Feel free to try other commands, and tweak accordingly.Code:$file = 'output.txt'; $cmdout = `/usr/bin/svnadmin verify /path/to/repo1 2&>$file`; $content = file($file); foreach ($contents as $line) { echo "<b>$line</b><br />"; }linux user # 503963
- 02-12-2010 #5Just Joined!
- Join Date
- Feb 2010
- Posts
- 3
Let's say I am running a game server which will be running constantly and I want to have a webpage that can be loaded and start showing it's output from the time the page loads forward. Basically, it will constantly be outputting messages of players who join and any server specific information. There is no user input really..
- 02-12-2010 #6
You could use a timed AJAX request to make an asynchronous HTTP requests to run the command.
JQuery is a great JavaScript library that will help with this, as well as some great presentation tricks.If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.
- 02-12-2010 #7
You would need some way of getting the output.
A simple way to do this would be to have the game server listen for a special connection to which it will repeat all output. Then you have a website that, on load, connects to the server on this port and prints all output it receives to the screen. This can be done with Javascript, which will use Ajax requests to get the latest output and add it to some section of the website.
Do you understand this?DISTRO=Arch
Registered Linux User #388732
- 02-13-2010 #8
I've just re-read my somewhat terse reply, so here is a quick and very dirty JQuery Ajax example. You will need to download and install Jquery and update demo.html to reflect the location / version.
Demo.html:
target.phpCode:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>Demo</title> <script type="text/javascript" src="/scripts/jquery-1.3.2.min.js"></script> <script type="text/javascript"> function makeAjaxCall(t) { $.ajax({ type: "GET", url: "target.php?typeOfCall=" + t, success: function(html) { handleAjaxResponse(html); } }); } function handleAjaxResponse(responseText) { if (responseText.length > 0) { responseText = responseText.replace(/^\s+|\s+$/g, ''); $('#dynamic').html("You have pushed my button " + responseText + " times."); } } </script> </head> <body> <div id="static" style="border-bottom: 5px double black; margin-bottom: 10px; padding-bottom: 10px;"> <h1>This div is static</h1> <p>It should not change when clicking the button. The dynamic div underneath will change though!</p> <input type="button" onclick="makeAjaxCall(true);" value="Clickit!" /> <input type="button" onclick="makeAjaxCall(false);" value="Reset Me!" /> </div> <div id="dynamic"> </div> </body> </html>
Code:<?php session_start(); if ($_GET['typeOfCall'] == 'false') { unset($_SESSION['howMany']); exit("no"); } if (!isset($_SESSION['howMany'])) { $_SESSION['howMany'] = 0; } $_SESSION['howMany']++; echo((string)$_SESSION['howMany']); exit(); ?>If we hit that bullseye, the rest of the dominoes will fall like a house of cards. Checkmate! (Zapp Brannigan)
My new blog. It's probably not as good as I think it is.


Reply With Quote