Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,582 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,926 people online right now. Registration is fast and FREE... Join Now!




How exactly does this line in the cmd work?

 
Reply to this topicStart new topic

How exactly does this line in the cmd work?, php myprog.php input.txt output.txt

godmoktail
5 Oct, 2008 - 05:34 PM
Post #1

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 17


My Contributions
Why put it on the line, meanwhile : php myprog.php would work because you have the code to read and write the files that you need (in this case input.txt and output.txt)?

Thanks in advance.
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: How Exactly Does This Line In The Cmd Work?
5 Oct, 2008 - 05:40 PM
Post #2

D.I.C Regular
***

Joined: 8 Aug, 2008
Posts: 383



Thanked: 23 times
My Contributions
PHP can take inputs, usually from the keyboard, and output results, usually to a browser. When you run it from the command line, you don't have either, so the inputs have to come from somewhere and the outputs need to go somewhere. That's what those files are for, because without them, it all has to go through the command line interface. While that's possible, it isn't always desirable.



User is offlineProfile CardPM
+Quote Post

godmoktail
RE: How Exactly Does This Line In The Cmd Work?
5 Oct, 2008 - 05:54 PM
Post #3

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 17


My Contributions
I understand that the files are needed, but they would be called for in the php code anyway (using fopen() ). So why would you mention them on the command line?
User is offlineProfile CardPM
+Quote Post

JackOfAllTrades
RE: How Exactly Does This Line In The Cmd Work?
5 Oct, 2008 - 06:11 PM
Post #4

Cantankerous Old Fart
Group Icon

Joined: 23 Aug, 2008
Posts: 580



Thanked: 59 times
Dream Kudos: 50
My Contributions
Because you want the user to be able to specify the names of the files to use, rather than hard-coding them in the script.
User is offlineProfile CardPM
+Quote Post

godmoktail
RE: How Exactly Does This Line In The Cmd Work?
5 Oct, 2008 - 06:18 PM
Post #5

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 17


My Contributions
So I wouldn't have to worry about location. But I would have to know to use those file names within the code. I get it.
Thanks.


User is offlineProfile CardPM
+Quote Post

godmoktail
RE: How Exactly Does This Line In The Cmd Work?
5 Oct, 2008 - 07:21 PM
Post #6

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 17


My Contributions
But how would I get the names if I didn't know what the user was going to type? For example, if someone types "php myprog.php 1.txt 2.txt", how would I get their file names? I want the code to be able to do it all the time with any file passed in.

Thanks in advance.
User is offlineProfile CardPM
+Quote Post

CTphpnwb
RE: How Exactly Does This Line In The Cmd Work?
5 Oct, 2008 - 09:31 PM
Post #7

D.I.C Regular
***

Joined: 8 Aug, 2008
Posts: 383



Thanked: 23 times
My Contributions
It's command line stin and stout. You don't worry about the names within your php code. You worry about getting the input in the file 1.txt lined up with what myprog.php is looking for, then the output goes to 2.txt instead of a browser. It's a bit cumbersome for my tastes, which is why I prefer to use a browser.


User is offlineProfile CardPM
+Quote Post

JackOfAllTrades
RE: How Exactly Does This Line In The Cmd Work?
6 Oct, 2008 - 03:29 AM
Post #8

Cantankerous Old Fart
Group Icon

Joined: 23 Aug, 2008
Posts: 580



Thanked: 59 times
Dream Kudos: 50
My Contributions
Here's the manual page on PHP command line usage. The number of command line arguments will be in the variable $_SERVER['argc'] (argument count) and the arguments themselves will be in $_SERVER['argv'] (argument vector).
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:41AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month