473,671 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

exec, system, passthru problem -- wrong output!

I've found a problem with exec, passthru, shell_exec & system.

I'm trying to run the following

exec("sort -r -n -k2,2 r1.txt > r2.txt")

with r1.txt being a numeric file. The file looks like this:

237 291 845 152 585 3
193 810 173 484 151 3
366 491 910 265 893 3
220 631 571 332 104 3
502 567 854 40 108 3
639 13 720 101 482 3
254 676 896 759 720 3
907 928 377 899 778 3
324 194 995 161 708 3
501 936 716 105 209 3

(The file is actually 1500 lines long, but this gives you an idea.
It's tab delimited, and the numbers are random: I created the file
using awk to test this).

Here's the problem:
If I run it with exec, passthru, shell_exec or system, THE FILE GETS
TRUNCATED. Instead of 1500 lines, I get 1338. But if I run the SAME
COMMAND in the shell (manually), THE SORT WORKS OK!

I run this in other files and the result is the same: the file gets
truncated. Also, I checked for special characters, but there are none:
the file contains just regular numbers and tabs. The problem seems to
be PHP since when I run the command manually I get correct results...

Any ideas?

Thanks.
Jul 17 '05 #1
3 3384
Jerry23 wrote:
I’ve found a problem with exec, passthru, shell_exec & system.

I’m trying to run the following

exec("sort -r -n -k2,2 r1.txt > r2.txt")

with r1.txt being a numeric file. The file looks like this:

237 291 845 152 585 3
193 810 173 484 151 3
366 491 910 265 893 3
220 631 571 332 104 3
502 567 854 40 108 3
639 13 720 101 482 3
254 676 896 759 720 3
907 928 377 899 778 3
324 194 995 161 708 3
501 936 716 105 209 3

(The file is actually 1500 lines long, but this gives you an idea.
It’s tab delimited, and the numbers are random: I created the file
using awk to test this).

Here’s the problem:
If I run it with exec, passthru, shell_exec or system, THE FILE GETS TRUNCATED. Instead of 1500 lines, I get 1338. But if I run the SAME
COMMAND in the shell (manually), THE SORT WORKS OK!

I run this in other files and the result is the same: the file gets
truncated. Also, I checked for special characters, but there are none: the file contains just regular numbers and tabs. The problem seems to be PHP since when I run the command manually I get correct results...
Any ideas?

Thanks.

Sounds impossible. PHP simply passes the command to the shell, so I
cannot think of a reason it would be truncated. Are you sure, very
weird. The only thing I can think of is that PHP puts some kind of
timing contraints on the command. Easy to test that, jut put a " &"
at the end of the command to have it run in the background, and not
subject to any timing constraints.

Another approach is to bring the output into php using the `---` as
in:
$a = `sort -r -n -k2,2 r1.txt`;
and see what $a looks like.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-exec-sys...ict125482.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=418020
Jul 17 '05 #2
steve wrote:
Jerry23 wrote:
>
> Here’s the problem:
> If I run it with exec, passthru, shell_exec or system, THE FILE GETS
> TRUNCATED. Instead of 1500 lines, I get 1338. But if I run the SAME
> COMMAND in the shell (manually), THE SORT WORKS OK!

Sounds impossible. PHP simply passes the command to the shell, so I
cannot think of a reason it would be truncated. Are you sure, very
weird. The only thing I can think of is that PHP puts some kind of
timing contraints on the command. Easy to test that, jut put a " &"
at the end of the command to have it run in the background, and not
subject to any timing constraints.


IIRC that won't remove the constraint - the process will get a SIGHUP on
timeout of the php script - you'd need to isolate it from the signal (with
nohup) or run it in a seperate process group (e.g. `at now
run_shell_comma nd`)

HTH

C.
Jul 17 '05 #3
Colin McKinnon <co************ **@andthis.mms3 .com> wrote in message news:<cc******* ************@ne ws.demon.co.uk> ...
steve wrote:
Jerry23 wrote:
>
> Here?s the problem:
> If I run it with exec, passthru, shell_exec or system, THE FILE GETS > TRUNCATED. Instead of 1500 lines, I get 1338. But if I run the SAME
> COMMAND in the shell (manually), THE SORT WORKS OK!

Sounds impossible. PHP simply passes the command to the shell, so I
cannot think of a reason it would be truncated. Are you sure, very
weird. The only thing I can think of is that PHP puts some kind of
timing contraints on the command. Easy to test that, jut put a " &"
at the end of the command to have it run in the background, and not
subject to any timing constraints.


IIRC that won't remove the constraint - the process will get a SIGHUP on
timeout of the php script - you'd need to isolate it from the signal (with
nohup) or run it in a seperate process group (e.g. `at now
run_shell_comma nd`)

HTH

C.


Colin, Steve:

OK Here's the deal: when I run them with & at the end (background), I
get the correct output. When I run them without the & I get the files
truncated. It looks like there's a problem with timing constraints as
you guys suggested.
I'll be following this problem (post it in some php dev list so
they're aware of the problem, etc).

Thank you for your help.

Jerry.
Jul 17 '05 #4

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

Similar topics

3
2671
by: rain | last post by:
Hello, I am having some serious problems executing a command on my redhat linux machine using exec, shell_exec, or any variants thereof. I have a string saved into a variable like: $mystring = "/usr/local/bin/lmc -e add /music/whatever.mp3"; Then I try to execute w/ something like:
17
2405
by: Piotr Wolski | last post by:
can anyone help me: using exec() function in PHP i can execute linux programms like ls,who and other, however i can not execute C programms and i really don't know why. Please help me, Peter
2
5277
by: Greg Chapman | last post by:
I am at my wit's end trying to get information out of Streamline.net's support dept about my problem. They reply quickly enough, but seem to try and give out the least possible amount of info each time. The transcript so far is reproduced for your amusement below. To summarise: I've put up a Sudoku-solving program called Sudoku.exe. I want to call it in a php script to solve a puzzle and output the solution. It works fine with...
2
2836
by: Martin Kofahl | last post by:
Hello, I'm slightly confused with the passthru() command. The program I call writes html headers itself. However, passthru() makes apache sending some generated headers first. There's no fault with spaches in the code etc, I think. Here's an simplified example: $ cat /www/example.php <?
2
1742
by: rickcasey | last post by:
I cannnot seem to get exec() or passthru() to execute a perl script; here's the code snippet: if ($debug) { echo "username1 = ".$username1."<br>"; echo "dbname = ".$dbname."<br>"; echo "SESSION = ".$_SESSION."<br>"; echo "Output file = ".$outputfile."<br>"; echo "Project name = ".$projectname."<br>"; echo "Study name = ".$studyname."<br>";
3
14893
by: Robert S | last post by:
I would like to display error messages put out by shell commands. For example the following code gives no output and the array $output has no values: <?php exec( 'lss', $output ); var_dump( $output ); ?> ...assuming that I don't have an executable called 'lss' on my computer.
4
12592
by: Tom | last post by:
I have a script which allows a user to upload a file. The script does some filename editing, mimetype checking, etc., and it's then supposed to send the file to a remote server, without any username/password prompt ( I have root access to both servers ). I'm trying to run an exec/passthru command using scp or rsync, but there's one fundamental question that I can't answer. When exec is called from the command line, e.g. `php...
1
4134
by: rickcasey | last post by:
I wonder if anyone has experienced something like this, as it seems truly bizarre and is causing me to tear out my hair (what little there is left of it).... The exec() function just suddenly stopped working, for no discernable reason. Here is the code: $execdir = $homedirectory."/".$genename."/".$rundir; // Run the Python script on the Exported text file(s).
7
2201
by: JahMic | last post by:
I'm having a problem with exec on my hosting server. Unfortunately, the hosting support seems to be anything but helpful. The following works fine on my localhost: <?php $MaskData = "mask.exe -e \"TestString\""; $Result = exec($MaskData, $Output, $ReturnValue); echo("Result: ".$Result);
0
8481
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...
0
8924
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8823
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7441
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6234
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
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...
1
2817
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
2058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1814
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.