Server Administration
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesServer Administration

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old February 15th, 2004, 03:52 PM
gigabyte gigabyte is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 19 gigabyte User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 42 sec
Reputation Power: 0
variables and command line

Hello:

I run acouple scripts via command line. Does anyone know how I can pass variables to my script via command line?

Reply With Quote
  #2  
Old February 15th, 2004, 05:19 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: variables and command line

Take a look at the getopt() function.

Reply With Quote
  #3  
Old February 15th, 2004, 07:55 PM
gigabyte gigabyte is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 19 gigabyte User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 42 sec
Reputation Power: 0
RE: variables and command line

thanks honcho, I kind of understand that.

For example in my browser I would run the script like such;

./mysript.php?Date=2003-02-15

What would I write as command line using getopt?

Reply With Quote
  #4  
Old February 15th, 2004, 09:52 PM
postalcow postalcow is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Ford CIty, PA USA
Posts: 1,267 postalcow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
Send a message via Yahoo to postalcow
RE: variables and command line

gigabyte,

Try using $argv[]

argv[0] will be the name of the script
$argv[1] will be the first parameter passed. Try it like this
make a file test.php
php Code:
Original - php Code
  1. #! /usr/bin/php -q
  2. <?
  3. echo "You Passed The Variable "."$argv[1] n n";
  4. ?>


chmod 755 the file then try it

./test.php a_variable_to_pass

It should print it for you.

The first line sets the interpreter -q tells it quiet so it does not print the PHP version stuff.

Reply With Quote
  #5  
Old March 3rd, 2004, 09:47 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: variables and command line

I have this same problem, and don't quite understand the above.

I have an older server that will pass the address lines' variables no worries. but my new one will not. Is this a new "feature" or is this an option in php.ini or another file?

Reply With Quote
  #6  
Old March 3rd, 2004, 09:56 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: variables and command line

It's all right, I didn't know about the $_GET coommand. I've never had to use it before, my old server just passed them right through.

Reply With Quote
  #7  
Old March 3rd, 2004, 09:57 AM
nawlej nawlej is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Dallas, Tx. USA
Posts: 2,008 nawlej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 7 m 51 sec
Reputation Power: 4
RE: variables and command line

I know in some cases just plain $0 is the script name, and $1 $2, etc....are the variables afterwords.

What you are reffering to by having to use the $_GET variable is because of a thing called "register globals". If they are turned on in the config file, the variables should pass straight through. They are probably off in the new configuration.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesServer Administration > variables and command line


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT