473,810 Members | 3,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2296
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**********@gm ail.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**********@gm ail.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_conten ts() 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**********@gm ail.com <we**********@g mail.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
2148
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 echo the contained variables: echo $var1 everything works fine. Now I want to execute the config by a php-script.
15
2159
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 to get all the obvious bugs out... Um... The script is at: http://ali.freezope.org/idf test and what it is supposed to show is at: http://ali.freezope.org/idf result
17
7931
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" requires user input to run; this causes the TCL script calling the PHP script to hose up and die. Is there a way I can do this so that the TCL script can call the PHP
3
1617
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 get access to the DBCC OUTPUTBUFFER). How do I give the SPROC permission to execute? Many thanks Edward
1
3122
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 for the output, the output save as .txt file was not in order unlike the output that was derrived from the query analyzer. As I try to solve my problem I observe that the lines separating the header and the data was the cause of un-order format, the...
1
2668
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 options are handled and the way input, output and error messages are reported. Program 'X' is a console application. I had it pretty well figured out, I thought, until I ran into a case where program X spit out ZIP code. In other words, I was...
4
2362
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 and selecting 'open with python', the execution occurs in my home directory, not my desktop. Is there a way to force py scripts to always run within the directory that they reside in? Thanks
9
4355
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). The browser then makes a new request to the server to redirect itself to abcd.asp after which the user gets redirected to abcd.asp. But in case of Server.Execute (or Server.Transfer), when the server
14
5417
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
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10393
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6882
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.