Find the answer to your Linux question:
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 ...
  1. #1
    Just 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

  2. #2
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    616
    linux user # 503963

  3. #3
    Just 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

  4. #4
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    616
    ok say you are running subversion, and want to verify a repo. you would do something like:

    Code:
     
    svnadmin verify repo1
    You can output that to a file.
    Code:
    2&>output.txt
    Now bring in PHP

    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 />";
    }
    Feel free to try other commands, and tweak accordingly.
    linux user # 503963

  5. #5
    Just 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..

  6. #6
    Trusted Penguin elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    2,298
    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.

  7. #7
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    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

  8. #8
    Trusted Penguin elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    2,298
    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:
    Code:
    <!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">&nbsp;</div>
        </body>
    </html>
    target.php
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...