473,763 Members | 3,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CLI ( command-line ) PHP displaying source code in-line when programis executed

Hi all,

I'm using PHP 4.4.2, and use PHP on both the command-line and the web.

I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using
Apache 2.0.55 , on my Dell laptop. Everything has been running flawlessly
without problems. Very amazing to use VMware, it has worked beautifully.

uname -a

Linux xxxxxxx 2.6.13-15.8-default #1 Tue Feb 7 11:07:24 UTC 2006 i686 i686 i386
GNU/Linux

php -v
PHP 4.4.2 (cli) (built: Feb 7 2006 20:13:29)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

php -m

[PHP Modules]
bcmath
bz2
calendar
ctype
curl
dbx
dio
domxml
exif
ftp
gd
gettext
gmp
iconv
mcrypt
mssql
mysql
ncurses
openssl
overload
pcre
posix
session
shmop
sockets
standard
sysvsem
sysvshm
tokenizer
wddx
xml
yp
zlib

[Zend Modules]
When I run the following program from the command line it prints out the
source code as well as the output from the program. I run other PHP programs
on the command-line and this doesn't happen. It's really peculiar. The
error output is below.

I copied this off of php.net, and have modified it only slightly to allow
command-line input. I was trying to find a CSV solution, which I ended up
finding elsewhere, but am curious why this program would error out the
way it does--have I misconfigured something? My php.ini is basically
unchanged, if at all. I think I might have set the path to mysql but that's
about it. When I run this program from the web it works without error.

<?php

if ( $argv[0] )
{
$file = $argv[0] ;
}
else {
$file = $_GET['file'] ;
print "<font face=arial>\n" ;
}

$row = 1;

$handle = fopen("$file", "r");

while ( ( $data = fgetcsv($handle , 1000, ",") ) !== FALSE )
{

$num = count($data);

print "$num fields in line $row:<br> \n";

$row++;

for ($c = 0; $c < $num; $c++)
{
print "$data[$c]<br> \n" ;
}

}

fclose($handle) ;

?>
=== COMMAND-LINE OUTPUT ===
1 fields in line 1:<br>
<?php<br>
1 fields in line 2:<br>
<br>
1 fields in line 3:<br>
if ( $argv[0] )<br>
1 fields in line 4:<br>
{<br>
1 fields in line 5:<br>
$file = $argv[0] ;<br>
1 fields in line 6:<br>
}<br>
1 fields in line 7:<br>
else {<br>
1 fields in line 8:<br>
$file = $_GET['file'] ;<br>
1 fields in line 9:<br>
print "<font face=arial>\n" ;<br>
1 fields in line 10:<br>
}<br>
1 fields in line 11:<br>
<br>
1 fields in line 12:<br>
$row = 1;<br>
1 fields in line 13:<br>
<br>
2 fields in line 14:<br>
$handle = fopen("$file"<b r>
r);<br>
1 fields in line 15:<br>
<br>
3 fields in line 16:<br>
while ( ( $data = fgetcsv($handle <br>
1000<br>
,) ) !== FALSE ) <br>
1 fields in line 17:<br>
{<br>
1 fields in line 18:<br>
<br>
1 fields in line 19:<br>
$num = count($data);<b r>
1 fields in line 20:<br>
<br>
1 fields in line 21:<br>
print "$num fields in line $row:<br> \n";<br>
1 fields in line 22:<br>
<br>
1 fields in line 23:<br>
$row++;<br>
1 fields in line 24:<br>
<br>
1 fields in line 25:<br>
for ($c = 0; $c < $num; $c++) <br>
1 fields in line 26:<br>
{<br>
1 fields in line 27:<br>
print "$data[$c]<br> \n" ;<br>
1 fields in line 28:<br>
}<br>
1 fields in line 29:<br>
<br>
1 fields in line 30:<br>
}<br>
1 fields in line 31:<br>
<br>
1 fields in line 32:<br>
fclose($handle) ;<br>
1 fields in line 33:<br>
<br>
1 fields in line 34:<br>
?> <br>


Feb 12 '06 #1
3 3037
Echo Echo,

At the beginning output $file. For some reason the file is reading
itself as input. If you are using:

php myprog.php infile.csv

....on the command line then I think you should be trying to get
"infile.csv " (or whatever) using $argv[1] not $argv[0]. Otherwise you
are passing the files own source to itself and the line

print "$data[$c]<br> \n" ;

Is causing the source to print.

-Robert

Feb 12 '06 #2
You're right!!

I'm smacking myself--too much coding!!

I changed it on my other progs but forgot to on this one.

Thanks!
rlee0001 wrote:
Echo Echo,

At the beginning output $file. For some reason the file is reading
itself as input. If you are using:

php myprog.php infile.csv

...on the command line then I think you should be trying to get
"infile.csv " (or whatever) using $argv[1] not $argv[0]. Otherwise you
are passing the files own source to itself and the line

print "$data[$c]<br> \n" ;

Is causing the source to print.

-Robert


Feb 12 '06 #3
On 2006-02-12, Double Echo <do********@you r.com> wrote:
Hi all,

I'm using PHP 4.4.2, and use PHP on both the command-line and the web. When I run the following program from the command line it prints out the
source code as well as the output from the program. I run other PHP programs
on the command-line and this doesn't happen. It's really peculiar. The
error output is below.
1 fields in line 1:<br>
<?php<br>
1 fields in line 2:<br>
<br>
1 fields in line 3:<br>
if ( $argv[0] )<br>
1 fields in line 4:<br>
{<br>
1 fields in line 5:<br>
$file = $argv[0] ;<br>
.....

<?php

if ( $argv[0] )
{
$file = $argv[0] ;
}
else {
$file = $_GET['file'] ;
print "<font face=arial>\n" ;
}


argv[0] is the name of the PHP script.

your program is reading itself and printing itself out.
use argv[1];

--

Bye.
Jasen
Feb 12 '06 #4

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

Similar topics

8
1333
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland newsgroups I learned that there is a function in stdlib.h called system. int system(const char *command); First question, is the system command ANSI compliant. Because I include <cstdlib> and write std::system(command.c_str()); it looks like an...
6
28199
by: Toralf Kirsten | last post by:
Hi, we are using db2 8.1 on Linux. I'd like to close all open connection at a defined time point. Therfore I wrote a sql script including the command disconnect all or release all
0
1117
by: Nadav | last post by:
Hi, I am writing an AddIn that adds a new EnvDTE.Command, upon setting a key for the command ( Command.Bindings = "Global::f12" ) an exception is being generated... Why can't I set a Key for the command? How could I resolve this problem???? ThanX Nadav.
1
3843
by: Mike | last post by:
Hello, How do I pass variables to a command text.(C#)Because of the quotes,it seems that the values are not passed. Thanks, Mike
3
2228
by: Anony Mous | last post by:
Hi, I've run into a problem. I've had postgres V8 beta on my WinXP Pro machine for some time now, and it's been running great. Now, for some reason, I cannot issue any queries to the database via psql. See snippit below... ------------ C:\Program Files\PostgreSQL\8.0-beta1\bin>createdb -U postgres test CREATE DATABASE
3
4852
by: Michael Roebuck | last post by:
Hi all I'm very new to VB - I am trying to run a DOS command from within a VB2005 asp.net web site using a command button? The DOS command will take the form of the command followed by several switches! Any ideas examples gratefully accepted.
5
1578
by: Jonay Aloat | last post by:
I know that I can use the news group to post questions. But last time, one of my friend show me that you can do the same thing using a unix command. I don't remember the command, but I know it is not "trn", or "archie". Can someone tell me what is the command? Thanks in advance; -Keal
1
1365
by: Sub-Lt | last post by:
Hello! We are upgrading one of our apps from VB6 to VS2005(VB). Barcode printing is part of the app. What we used to do is send the printer command directly to the printer. Printer.print {long printer command} would work. Since that doesn't exist anymore, how do we go about sending this printer command to the barcode printer? The drawstring meathod prints the command as an actual string on the barcode. I think it sees it as a graphic...
3
7016
by: Vlad | last post by:
I am trying to run the dos command "rename C:\Temp\MyTest1.txt MyTest2.txt" from VB.net - to use the shell command I have found I have to use a bat file otherwise I get an "The system cannot find the file specified" error. I am trying to use Dim MyProcess As New ProcessStartInfo MyProcess.FileName = "ren" MyProcess.Arguments = "C:\Temp\MyTest1.txt MyTest2.txt"
2
2127
by: black_13 | last post by:
how do i exec a command (such as xcopy) from with win32 python and wait on that command to come to completion? and also cleanly terminate the command shell? thanks black_13
0
10145
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
9998
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...
1
9938
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
9822
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
8822
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
7366
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
6642
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
5270
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...
3
2793
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.