Jump to content

[SOLVED] system command dump


jaymc

Recommended Posts

I am running a php script via the command line, for example

 

php -f script.php

 

However, it is forcefully outputting the return of the command, without me echoin it etc

 

Here is script content

 

<?
        $command = "/usr/sbin/apachectl configtest";
        $result = shell_exec($command);
?>

 

I want $result to contain the output from the $command, at the moment, it does not and the output from the command is forcefully dumped

 

In the manual, it is meant to output the return to the given VAR. This is not working. I have tried system, exec, passthru

 

They all do the same

 

Any idea why?

Link to comment
Share on other sites

What does the output look like?

 

Maybe you need to redirect stderr and stdout.

 

<?php
        $command = "/usr/sbin/apachectl configtest &> /dev/null";
        $result = shell_exec($command);
?>

Link to comment
Share on other sites

That stopped it from forcefully outputting, but did not send the output to the VAR

 

<?
        $command = "/usr/sbin/apachectl configtest &> /dev/null";
        passthru($command, $result);
echo $result;
?>

 

The output of $result was "0", not sure why as the reuslt of the command is "Syntax OK"

 

Any more ideas?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.