473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Execute script and catch output

In PHP I need to be able to execute another script from inside another
and catch the output. How do I do this? The require() and include()
functions will execute a script, but it sends the output to the
browser, I don't want this. I need to be able to catch the output and
store it in a file or perform logic on it.

I've tried doing fopen and hitting the script that way, but the problem
is that doing this kills the session state as if I were a 3rd party
user accessing the system. Any ideas?

Aug 18 '05 #1
4 2268
On Wed, 17 Aug 2005 20:42:06 -0700, werdna.sivad wrote:
In PHP I need to be able to execute another script from inside another
and catch the output. How do I do this? The require() and include()
functions will execute a script, but it sends the output to the
browser, I don't want this. I need to be able to catch the output and
store it in a file or perform logic on it.

I've tried doing fopen and hitting the script that way, but the problem
is that doing this kills the session state as if I were a 3rd party
user accessing the system. Any ideas?


Try popen?
Aug 18 '05 #2
we**********@gmail.com wrote:
In PHP I need to be able to execute another script from inside another
and catch the output. How do I do this? The require() and include()
functions will execute a script, but it sends the output to the
browser, I don't want this. I need to be able to catch the output and
store it in a file or perform logic on it.

I've tried doing fopen and hitting the script that way, but the problem
is that doing this kills the session state as if I were a 3rd party
user accessing the system. Any ideas?

It won't if you don't tell it to. You can use Require and Include but
just don't have any echo's or print's in the file have only variables.
then grab the variables in the file that required them.
Aug 18 '05 #3
we**********@gmail.com wrote:
In PHP I need to be able to execute another script from inside another
and catch the output. How do I do this? The require() and include()
functions will execute a script, but it sends the output to the
browser, I don't want this. I need to be able to catch the output and
store it in a file or perform logic on it.

I've tried doing fopen and hitting the script that way, but the problem
is that doing this kills the session state as if I were a 3rd party
user accessing the system. Any ideas?


Its not very clear what you're trying to acheive here. Taking a wild stab in
the dark....you want to access the page but using the same session id? If
so, you just need to either pass the sessionid in the request variables or
tell the target page that you have it in a cookie. The former can be done
(using GET vars) with the file() and file_get_contents() functions
(assuming config allows it) while the latter needs the libcurl extensions
in PHP (or a lot of coding).

C.
Aug 18 '05 #4
On 2005-08-18, we**********@gmail.com <we**********@gmail.com> wrote:
In PHP I need to be able to execute another script from inside another
and catch the output. How do I do this? The require() and include()
functions will execute a script, but it sends the output to the
browser, I don't want this. I need to be able to catch the output and
store it in a file or perform logic on it.


ob_start();
require 'somefile.php';
$output = ob_get_contents();
ob_clean();

Be aware that Output Buffering doesn't stop headers being sent out.

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
Aug 18 '05 #5

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

Similar topics

1
by: Arne Lund | last post by:
I've to read variables out of a config-file, that is stored on a Linux-machine. When I connect to the server with puTTY, I can execute the config with: .. /usr/local/webspace/config then I can...
15
by: greenflame | last post by:
First of all I only have IE for testing. Ok. I have a script that is supposed to show, not evaluate, the indefinite integral of something. When I run the script it just craches IE. I have tried...
17
by: comp.lang.tcl | last post by:
The TCL command I am using will do a command-line action on a PHP script: set cannotRunPHP I have to do it this way as both the TCL script and the PHP script run as CLI. However, "info.php"...
3
by: teddysnips | last post by:
I'm trying to use the SPROC below (courtesy of Erland!) to capture the error message but it fails owing to insufficient permissions (I can't reproduce it just now, but I think it's because it can't...
1
by: Alfred | last post by:
Hi Guys, anyone out there who could help me with my problem? I have created a .bat file that would execute the mssql script and give an .txt file as an output. The script run successfully except...
1
by: Tony Freixas | last post by:
Hello, I'm trying to create a wrapper for a program. I want to execute program 'X' by running program 'Y', such that 'Y' appears to function pretty much like 'X' both in the way command line...
4
by: brad | last post by:
When I use idle or a shell to execute a python script, the script executes in the directory it is currently in (in this case, my desktop). However, when using GNOME and right clicking the py script...
9
by: RN1 | last post by:
When a server encounters the line Response.Redirect("abcd.asp") in a ASP script, the server tells the browser that it has to be redirected to another page (which is abcd.asp, in this case)....
14
by: asdf | last post by:
I have a python script whose output i want to dynamically display on a webpage which will be hosted using Apache. How do I do that? thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...

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.