473,386 Members | 1,775 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,386 software developers and data experts.

Getting script pathname in a script run from the command line

Hi,

I have a PHP script running in a Cron job in Unix, using the "php"
command-line command executable. How do I get the path to the script,
from within the script? I've tried all the $_SERVER[] variables to no
avail.

Jamie
Jul 17 '05 #1
2 1646

James Pittman wrote:
Hi,

I have a PHP script running in a Cron job in Unix, using the "php"
command-line command executable. How do I get the path to the script, from within the script? I've tried all the $_SERVER[] variables to no avail.


Have you tried $argv[0]

Ken

Jul 17 '05 #2
James Pittman napisa³:
Hi,
Hello
I have a PHP script running in a Cron job in Unix, using the "php"
command-line command executable. How do I get the path to the script,
from within the script?
Do you mean the filename of the script, like
"/foo/bar/whatever/script.php"?
Then you should use the __FILE__ superconstant. It holds the filename of
the currently executing script.
BUT that means, that if you have:

# in test_script.php:
<?php
echo 'First echo: ' . __FILE__ . '<BR>';
?>

# in host_script.php:
<?php
include ('test_script.php');
echo 'Second echo: ' . __FILE__;
?>

you will get:
First echo: (...)/test_script.php<BR>
Second echo: (...)/host_script.php

Chech the www.php.net page for more info on __FILE__ constant, you will
get a lot of useful hints there. AFAIR they have something in the "See
also:" section, that will give you always the "host_script.php".
I've tried all the $_SERVER[] variables to no
avail.
Nope, it won't work. These are only set in a webserver enviroment; forget
about them in a command-line parser.

Jamie


HTH
Mike
Jul 17 '05 #3

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

Similar topics

4
by: MK | last post by:
I'm working with IIS on W2K server. I'm trying to use module "wmi" in a CGI script but with no success. The following works: import cgitb; cgitb.enable() cgi.test() .... but the...
5
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of...
10
by: Chris Martin | last post by:
Background: Our main menu is built using a simple unordered list containing other ULs. There is a table on a page that holds the subnav. Because of certain circumstances, I need to build the subnav...
6
by: Lucas Cowald | last post by:
Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2 -p Can you show me a code how to run this...
2
by: ern | last post by:
My command-line application must be able to run text scripts (macros). The scripts have commands, comments, and flags. Comments are ignored (maybe they are any line beginning with " ; ") Commands...
2
by: Lucas Malor | last post by:
Hello all. I'm trying to do a little script. Simply I want to make a list of all options with them default values. If the option is not specified in the command line, the script must try to read it...
51
by: Ojas | last post by:
Hi!, I just out of curiosity want to know how top detect the client side application under which the script is getting run. I mean to ask the how to know whether the script is running under...
4
cassbiz
by: cassbiz | last post by:
Could use some help here. This script is carrying over an image just fine but the text isn't coming over. can you see why it is not working???? from the form I want to carry over two lines of...
0
by: BruceMcF | last post by:
On Apr 16, 6:03 pm, "Aaron Gray" <ang.use...@gmail.comwrote:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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,...
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
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...

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.