Passing Parameter In Command Line

Apr 30, 2003

Can somebody tell me how can I pass a parameter to a PHP script in de command line?
for instance: bin]# ./print_listname 18

//$list_number = // parameter var;
echo $list_number;?>

View 1 Replies


Cli - Passing A String Via The Command Line

Ancient old crusty decided to try PHP a week or so ago. Signed up with a provider who offer PHP. Bought book. Mastering PHP.. first few pages give example of passing a string via the command line. Code:

View 4 Replies

Passing $_POST Variables To Command Line Php

I'm trying to test some php script using the command line php.exe. Is there any way to pass the $_POST variables? I know how to pass the $_GET variables, but I don't know how to do this for the $_POST ones.

View 1 Replies

Passing GET/POST Variables Via Command Line?

How does one pass GET/POST variables via command line? For instance setting $getv=100 with a command line execution of test.php.

View 8 Replies

Passing $_GET, $_POST Variables To Command Line Php

I'm trying to test some cgi php, but do not have access to a webserver (in
any way, shape, or form). I've been trying to fudge testing by using the
CLI php.exe in the windows distribution.

I've read all the faqs about the CLI and I'm not sure if there is any way to
pass the $_GET and $_POST variables. I have yet to find any information on
this topic online, either.

If anyone has any ideas of how to do this or a better way to test, please
let me know.

View 7 Replies

Command Line Interface Passing In Multiple Files?

I'm familiar with the basic of CLI and $argv array with php. Example:

<?php // test.php
$php test.php datafile.txt 10 100

will produce:

array(4) {
string(8) "test.php"


What I'm trying to do is pass all files in a directory *.txt to php. Is there way I can do $php test.php *.txt and have all the filenames stored in an array?

$files = glob($argv[1]);

View 1 Replies

Tracert :: Passing Command To Command Prompt Via Exec

I want to execute a "tracert" command in the command prompt via php (using windows)

I've managed to use passthru() to open the command prompt (but it doesn't allow me to use it) and when I close it, it outputs the command prompt output in the browser.

I don't mind whether the result is passed back to the browser to stays in the command prompt window (but that would use exec() I would think).

So how can I tell the command prompt that launches to execute the line


So far my experimental code is:


EDIT: my backslashes have been stripped from the path, but you know what I mean!

View 3 Replies

Linux - Executing System Command In Differs When Using Browser And When Using Command Line?

I have to execute a Linux more command in PHP from a particular offset, format the result and display the result in the browser.My code for the above is:



The output at the browser is: No of lines are : 3428 (This is wrong)While executing the same command using command line gives a different output.My code snippet for the same is:
$moreCommand = "more +3693 /var/log/apache2/access_log | grep -v -e '.jpg' -e '.jpeg' -e '.css' -e '.js' -e '.bmp' -e '.ico'| wc -l";


The output at the command line is: No of lines are : 279 (This is correct)While executing the same command directly in command line, gives me output as 279.I am unable to understand why the output of the same command is wrong in the browser.Its actually giving the word count of lines, ignoring the offset parameter.

View 2 Replies

Linux - Execute Command From Command Line But Not From PHP Exec()?

I have done some creative searches and am kind of hitting a road block.

I am trying to use the linux program "sox." I am trying to call it from my PHP script. The script DOES work if I use the command line. However, when I use PHP exec, it does not work.


sox file1.mp3 file2.mp3 tempfile.mp3 -V3

("V3" specifies a verbose output)

When executing in the command line as "User X" or as root, I am able to create the new file. However, when I execute the command as:

exec('sox file1.mp3 file2.mp3 tempfile.mp3 -V3', $output);
foreach($output as $line){
print $line;

It does not generate the new file. Furthermore, the array that should return the results of of the command is blank.

I have done a simple text with


and i get the contents of the root directory.

I used the PHP command get_current_user() and it returned the owner of the directory that is the root of the web site.

However, when I use the linux command whoami I found out that it views the current person as "apache." Would I need to give apache the rights to use the program?

I will continue to search online and do trial and error in an effort to figure out what I am doing wrong.


I am not in safe mode (I checked the
phpinfo() page")

View 3 Replies

Command Works From Command Line But Not Through System(),exec()?

PHP script which changes the date/time and timezone.The date and time change just fine, but I cannot get the timezone to change through the script.If I type the same command at a DOS prompt it works.This only runs on a closed server (client and host are always the same) so security is not an issue.I've checked that PHP is not in safe mode and I have tried using all options to run a command that I know of (system(), exec(), shell_exec(), passthru()).This is running on XP Pro SP3.

Here is my script:
$timezone = $_POST['timezone'];
$time = $_POST['time'];
$date = $_POST['date'];


this specific command would not work?A PHP setting?Syntax?Windows Permissions?

View 3 Replies

Run An External Program In (via Command Line) Using Shel_exec Command?

basically i want to run an external program in PHP (via command line) and to do that i am using shel_exec command.

I understand that the shel_exec takes "String" parameter and my problem is exactly here:

I am trying to pass a variable (containing a file name) to the shel_exec, however it is not working. If I just type the content of my variable (i.e. file name) it will work but not when I am using the variable. here is the part of the code i am working in:

$output = shell_exec('java -jar C:/htmltolatex-1.0.1/htmltolatex.jar -config C:/htmltolatex-1.0.1/config.xml -output C:/ConversionTest/output.tex -input' .$pAddress);

$pAddress is my variable which I want to pass.

I have tried to print out "$pAddress" to make sure it is actually containing what I think it contains and it was fine; it DOES contain the file name, However when it is used inside the shel_exec it is not working.

View 2 Replies

Use Mcrypt_decrypt From Commond Line - Error - Call To Undefined Function Mcrypt_decrypt() In Command Line Code On Line 1?

i m trying to use mcrypt_decrypt from commond line but i m getting the folllowing error:-

Call to undefined function mcrypt_decrypt() in Command line code on line 1

and any other alternative solution because i m using os:cmd() from erlang to achive this.since erlang do have function to achieve this but i m unable to figure out whats worng in thought of doing like this so that i verify the things.

View 3 Replies

Run Phpunit Command In Windows Command Line?

all examples of phpunit I saw run the simple command line tool:phpunit TestClass
but when I try the same on a directory other than the xampp php dir, I end up getting an "unknown command."Is there a way to execute the phpunit command from any directory in the Windows command line?

View 1 Replies

CLI ( Command-line ) PHP Displaying Source Code In-line When Programis Executed

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

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]

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, 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.


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

$row = 1;

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

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

$num = count($data);

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


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

View 3 Replies

Output Multiple Line Command-line Outputs As Different Lines?

PHP: Output multiple line command-line outputs as different lines. Sorry if the title is difficult to understand. Basically I want my output like A, instead of B. It currently looks like B. I have tried nl2br. The script I am trying to run is:

echo "Virus Scan Results:";
$scanme = system('cd /var/www/upload/files; clamscan --remove=yes '.$furl);


View 3 Replies

Phpunit Run From Command Line Returns "'phpunit' Is Not Recognized As An Internal Or External Command Operable Program Or Batch File?

When I run phpunit on the command line I get 'phpunit' is not recognized as an internal or external command, operable program or batch file.

php has been added to my system path.
My php.ini includes include_path=".;C:PHPpear".

How can I get the command phpunit to be recognized by the command line?

View 2 Replies

Title= Parameter In Echo Command?

how to do so that the parameter title= accepts a variable rather than a constant in the following :

echo '<a id="thumb'.$i.'" href="full%20('.$i.').jpg" class="highslide" onclick="return hs.expand(this)">
<img src="thumb%20('.$i.').jpg" alt="M'.$i.'" title=$libx /></a>'."

When I execute this echo, the result for title= is $libx instead of the content of $libx.

View 2 Replies

Cli - Command Line Progress Bar - Add Progress Bar To Command Line Script?

I am currently trying to add a progress bar to a command line script and I've tried various solutions (including Zend and Console_ProgressBar). The problem they both have in common is that the progress bar doesn't stick at the bottom of the window because during the script, new lines and other information is outputted. Is there any way to keep the progress bar at the bottom of the terminal but still be able to output other information while the script is running? [Edit] I figured it out: Instead of outputting directly to STDOUT I am actually grabbing the output inside a variable, I erase the screen with echo chr(27) . '[2J' and then output to STDOUT the contents of the variable and then append my progress bar.

View 1 Replies

DAL Library Which Has The Similar .Net's Feature: Command.Parameter?

ood DAL library for PHP which has the similar .Net's feature: ommand.Parameters.AddWithValue("@demographics", demoXml).mysqli extension is good but I want to have the aforementioned feature too. Putting many "?" does not look nice and rather confusing when a table has many fiends (>= 8).

View 1 Replies

Parameter Passing From Asp To Php

I've got a script using com objects that will work in asp but not work
with php.

The asp script creates an object that does something and returns a
string. I want this sting to be passed to an php script without
putting it in a getstring. The getstring will expose the value and
thats not my intention. Encryption is an option but I'm not charmed by
that solution. I'd rather do it behind the scenes.

Who knows a creative way to do this?

View 3 Replies

Passing A URL As A URL Parameter?

I am implementing OpenId login in a CakePHP application. At a certain point, I need to redirect to another action, while preserving the information about the OpenId identity, which is itself a URL (with GET parameters), for instance[URL]How do I pass this data? The first attempt would be

function openid() {
$this->redirect(array('controller' => 'users', 'action' => 'openid_create', $openid));


View 3 Replies

Parameter Passing

I am unable to pass my php parameter to the javascript. But it is not getting fetched.

$str="from¬ php";

var¬ abc="<?php¬ echo($str)¬ ?>"


View 6 Replies

Exec() Passing Parameter

(I have a PHP script (A) that execute in the background a another PHP script(B) and also send a parameter the $id like that:

View 3 Replies

PATH_INFO Parameter Passing

I'm trying to work out how to pass a parameter to a PHP script so that I can use a URL as simple as:

where "john" is actually a value to be passed to a script called index.php In other words, the full conventional URL of this would have been:

I've got as far as using the PATH_INFO environment variable to capture parameters from a URL like:

but would like to be able to eliminate either the ".php" bit from "index.php", or the whole thing altogether. I know this is possible because I've seen plenty of sites use this URL style. I'm wondering if this involves messing with the DNS setup, which won't be possible for me as I'm running on a name-based shared server.

View 1 Replies

Function Parameter Passing

I wrote a function that did not seem to work so
I checked whether the parameter I was passing to the function was
actually being used. I found that it wasn't. When I run the following
code I get:


and nothing else. It seems that the variable is not being passed to
the function. Here is the code:

function file_write_position($textcheck) {
print "Testcheck: " . $testcheck . "<br>


$testcheck="# Test Call Area";

View 3 Replies

Passing Parameter Problem

I'm having a simple problem here. Here is a simple file test.php

<?php echo "My Name is " . $name . "
"; ?>

When i try to load the file with iexplorer ---->


I get the text My Name is but not Gregory. I'm running Apache2 and my php worked fine untill this.

View 3 Replies

Copyrights 2005-15, All rights reserved