LinuxQuestions.org
Review your favorite Linux distribution.
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 12-12-2005, 06:27 PM   #1
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676
Blog Entries: 7

Rep: Reputation: 32
How to conserver spacings from shell to php


Hi I want to display the output of the command top in a list .......the user chooses an option from the list and kills the corresponding process (never mind about security ...it is a private project).
The output of my command prints neatly as follows in php when I use echo $reply,

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2264 root 16 0 111m 60m 4124 R 25.3 24.3 29:54.20 X
2756 ali 12 0 62556 58m 19m R 8.4 23.2 12:01.73
1 root 8 0 76 68 44 S 0.0 0.0 0:04.37 init
2 root 9 0 0 0 0 S 0.0 0.0 0:00.27 keventd
3 root 19 19 0 0 0 S 0.0 0.0 0:00.01
10 root -1 -20 0 0 0 S 0.0 0.0 0:00.00

EDIT: ACTUALLY THEY GET DISPLAY NEATLY NOT THE WAY THEY ARE DISPLAYED ABOVE...BUT WHEN I POST THE OUTPUT GETS SCRAMBLED

but if I take $reply and explode() it into an array and then use each element in the array as a row in the list....it works fine exept that the spacing and identing in each row gets lost:

2 root 9 0 0 0 0 S 0.0 0.0 0:00.27 keventd
3 root 19 19 0 0 0 S 0.0 0.0 0:00.01
10 root -1 -20 0 0 0 S 0.0 0.0 0:00.00

Beneath is the code for my second scenario (Iam a self taught newbie so be mercifull :P)

<?
$command = "sudo top -b -n 1";
$reply = shell_exec($command);
$processArray = explode("\n",$reply);
for($j = 0; $j < sizeof($processArray); $j++)
{
$current = "<pre>$processArray[$j]<pre>";
?>
<select size = "<?= sizeof($processArray) ?>">
<option value = <?= $j ?> > <?= $current?></option>
<?
}
?>
</select>

Last edited by ALInux; 12-12-2005 at 06:30 PM.
 
Old 12-12-2005, 06:38 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Why not put the rows and values in a html table ?
 
Old 12-13-2005, 07:04 AM   #3
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676

Original Poster
Blog Entries: 7

Rep: Reputation: 32
Because the idea is to allow the user to kill a process ...if I use a list the user can only choose one "existing" process...i.e. his choice is fool proof...
 
  


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
[PHP] Sending shell commands from PHP pEeDy Programming 4 11-04-2005 08:06 PM
Conserver setup........Help sal_paradise42 *BSD 0 06-17-2005 10:32 PM
PHP and Shell scripts haze Programming 4 04-15-2005 02:52 AM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 11:51 AM
Shell access thru php ka_alucard Slackware 1 05-25-2003 05:29 AM

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

All times are GMT -5. The time now is 09:22 PM.

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