473,569 Members | 2,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Output shown only in Command line and not in browser

I have the following code in a script
--------------------------------------------------------------------------------------------------------------------------------
foreach($server list as $sno=>$serverda ta) {
$servername = $serverdata['name'];
if($servername) {

unset($outputst r, $outputarr);
$outputstr = exec("ssh -n ".$serverna me." 'fstat | wc -l'",
$outputarr);

echo
"\r\n----------------------------------------------------------";
echo "\r\nssh -n ".$serverna me." 'fstat | wc -l' ";
echo "\r\nserver name = ".$serverna me;
echo "\r\noutput str = "; var_dump($outpu tstr);
echo "\r\noutput arr = "; var_dump($outpu tarr);

}
}
--------------------------------------------------------------------------------------------------------------------------------

When executed from browser it displayed:

---------------------------------------------------------- ssh -n
192.168.0.155 'fstat | wc -l' servername = 192.168.0.155 outputstr =
string(0) "" outputarr = array(0) { }
---------------------------------------------------------- ssh -n
192.168.0.156 'fstat | wc -l' servername = 192.168.0.156 outputstr =
string(0) "" outputarr = array(0) { }
---------------------------------------------------------- ssh -n
192.168.0.159 'fstat | wc -l' servername = 192.168.0.159 outputstr =
string(0) "" outputarr = array(0) { }
--------------------------------------------------------------------------------------------------------------------------------

When executed from command line it displayed:

PHP Warning: Module 'ctype' already loaded in Unknown on line 0
PHP Warning: Module 'SimpleXML' already loaded in Unknown on line 0
PHP Warning: Module 'dom' already loaded in Unknown on line 0
PHP Warning: Module 'iconv' already loaded in Unknown on line 0
PHP Warning: Module 'pspell' already loaded in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030-debug/ssh2.so' -
/usr/local/lib/php/20041030-debug/ssh2.so: unsupported file layout in
Unknown on line 0
PHP Warning: Module 'pcre' already loaded in Unknown on line 0
PHP Warning: Module 'xml' already loaded in Unknown on line 0
bash: fstat: command not found
Password:

----------------------------------------------------------
ssh -n 192.168.0.155 'fstat | wc -l'
servername = 192.168.0.155
outputstr = string(8) " 340"

outputarr = array(1) {
[0]=>
string(8) " 340"
}

----------------------------------------------------------
ssh -n 192.168.0.159 'fstat | wc -l'
servername = 192.168.0.159
outputstr = string(1) "0"

outputarr = array(1) {
[0]=>
string(1) "0"
}

----------------------------------------------------------
ssh -n 192.168.0.156 'fstat | wc -l'
servername = 192.168.0.156
outputstr = string(8) " 530"

outputarr = array(1) {
[0]=>
string(8) " 530"
}
--------------------------------------------------------------------------------------------------------------------------------

Why the variables are only displayed when executed from command line
only and not from browser.

I have tried using sleep() command after exec(), but no change.
$outputstr = exec("ssh -n ".$serverna me." 'fstat | wc -l'",
$outputarr);
sleep(2);
Thanks.
Manish

Jun 29 '06 #1
1 3376
On 28 Jun 2006 23:04:20 -0700, "Manish" <ye*********@gm ail.com> wrote:
Why the variables are only displayed when executed from command line
only and not from browser.


Most likely, differences in user permissions and environment variables between
your commandline and the webserver environment.

--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jun 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3166
by: lkrubner | last post by:
I'd like to write a PHP script to be used from the command line on a Unix machine. I'd like for the script to put together a string, turn it into a web page, print it, then return control the command line. Obviously it is quite easy to make a string that is valid HTML and send it to the printer. The tough part is making look like a web page....
2
3161
by: Ben Chivers | last post by:
I have a problem, which I think can be easily solved somehow. I am trying to execute a C program through using a PHP script. I do this by sending an exec command from the PHP script. My PHP script is printed below: <?php system('main.exe');
5
2161
by: Tom Lam lemontea | last post by:
Hi all, This is my very first post here, I've seriously tried some programming on C, and shown below is my very first program(So you can expect it to be very messy) that I wrote after I've learned the basics. However, the output function I wrote seems to repeat unneedingly for 2 times. My trial on solving it myself have failed. Anyone willing...
3
1220
by: Progalex | last post by:
Hi everybody! I'm creating a very simple VB .NET application that needs to launch the command line ml.exe compiler. At the moment I'm redirecting ML's output to a text file and then my app reads its content and puts it to a textbox for the results. Is it possible to redirect ML's output as VS does, I mean the output given line by line...
2
4741
by: Steve | last post by:
I have created a console app that simply prints out a message a couple times, then exits, here is the code: <code> for(int i = 0; i < 10; i++) { System.Threading.Thread.Sleep(500); Console.WriteLine(String.Format("Sleeping...{0}", i)); } Console.WriteLine("Done!"); </code>
0
19264
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a hell of a time with it... The following comes from phpinfo(): PHP Version: 5.1.2 mysql Client API version: 5.0.18 mysqli Client API version: 5.0.18
5
11392
by: Mikko Nylén | last post by:
Hi!, I'm trying to read the output of an process as it gets executed and append the output to a RichTextBox. However, I have a little problem: the process I'm trying to execute is a Python script, which uses the time.sleep() to sleep for a specified amount of time. This (the use of time.sleep()) seems to have the side effect of the...
6
1543
by: Goran07 | last post by:
Hello, all, I see there are some true experts here on the forum, so maybe someone can help me. I need to get output from DOS application that does some calculations based on the choices that user makes in it. Thre are 4-5 choices to choose, and then the calculated data is either printed or shown on the screen. Printing works just fine, however...
2
2750
by: yogeshbhandare | last post by:
Hi Friends I have an issue with shell_exec. I am trying evoke a command from browser. The command get executed properly without any issue however it deos not return all the output which is shown on when I try to execute the same command in the DOS shell. The details are as follows : When I execute that command the output seen...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.