Path issue

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
quantumnube
Forum Newbie
Posts: 3
Joined: Sun Jul 03, 2016 3:34 am

Path issue

Post by quantumnube »

Hello everyone,
I ran into an issue and dont have an explanation for it.
Trying to get global command prompt access for composer using the terminal.
First I set the path in the environment and rebooted, (windows) and checked it ok.
Next I made a little hiworld.php file and for the test put it file in the same dir as php.exe.

Thinking I had global capabilities I entered php hiworld.php from C:\ and get Could not open input file.
changed into the same dir as the hiworld.php and php.exe and it worked.
went back to the C:\ typed 'd' ^z and it echoed back: 'd'
Then typed php C:\dir0\dir1\dir2\hiworld.php it worked
Then typed php C:\dir0\dir1\dir2 hiworld.php it did not work Could not open input file

Whats perplexing is that a dos batch file and php 'd' both echo back from C:\
but it wont execute the .php file from C:\ unless I include the whole path? I assume that is the problem I am running into with composer as well?

I thought all I'd have to do is type php hiworld.php from anywhere and it would have worked like a dos batch file? An explanation escapes me.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Path issue

Post by requinix »

The "global command prompt access" thing only applies to finding php.exe. When you tell PHP to run "hiworld.php" it's going to look in the current directory. Not PHP's directory, not in the global path, just where you are at that moment. If you give a full path to the file it will work, obviously. If you say

Code: Select all

php C:\dir0\dir1\dir2 hiworld.php
then you're telling PHP to run the "C:\dir0\dir1\dir2" script and pass it an argument of "hiworld.php". Which is not at all what you want to do.

The exact same thing happens with composer: if you run "php composer.phar" then composer.phar must be in the current directory.

I don't know what you think batch files do differently. They work the same way.
quantumnube
Forum Newbie
Posts: 3
Joined: Sun Jul 03, 2016 3:34 am

Re: Path issue

Post by quantumnube »

Code: Select all

php C:\dir0\dir1\dir2 hiworld.php
Interestingly in the expression above php does not assume the missing '\' and it has to be the full path to work as below. That seems odd to me but....

Code: Select all

php C:\dir0\dir1\dir2\hiworld.php


In doing more tests found it differs from a dos batch file in that a batch file, as long as its in the windows environment path will execute from any directory just by entering the filename in the command prompt where php, as you said, only executes if you are in its current directory or use the full path statement with the command. Thanks!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Path issue

Post by requinix »

quantumnube wrote:

Code: Select all

php C:\dir0\dir1\dir2 hiworld.php
Interestingly in the expression above php does not assume the missing '\' and it has to be the full path to work as below. That seems odd to me but....

Code: Select all

php C:\dir0\dir1\dir2\hiworld.php
Because they're two completely different things. Did you not read what I said earlier?
quantumnube wrote:In doing more tests found it differs from a dos batch file in that a batch file, as long as its in the windows environment path will execute from any directory just by entering the filename in the command prompt where php, as you said, only executes if you are in its current directory or use the full path statement with the command. Thanks!
Again, as I said, the path thing only affects the program you are invoking. php.exe. This magic batch file you keep talking about is either changing the working directory or calling a program which looks for files in a different way than PHP (and, in fact, nearly all programs).
Post Reply