Jump to content

Recommended Posts

Hi,

 

I'm having a weird issue when I try to run PHP scripts from the command line on my server.  I'm trying to just run a very simple script to test it out:

 

#!/usr/bin/php-cgi -q
echo "Hello terminal\n"; 

 

And I get the following error in the terminal..

 

Error in argument 1, char 3: option not found
Usage: php-cgi [-q] [-h] [-s] [-v] [-i] [-f <file>]
       php-cgi <file> [args...]

 

When I try taking out the quiet (-q) parameter, I get the following error..

 

-bash: ./socket_server.php: /usr/bin/php-cgi^M: bad interpreterNo such file or directory

 

As you can see, in the second example, a rogue "^M" was appended to the end of the first line of my socket_server.php file.  What does ^M correlate to?  I realize it is a character code for something that can't be represented with an actual character, but I don't know what it is, and I'm not sure why it is being appended to the end of my first line.

 

My assumption is that this is happening in the first example too, which is why I get the "error in argument 1" message, since undoubtedly -q^M is an invalid argument...

 

Any help is greatly appreciated!

 

nethnet

Link to comment
https://forums.phpfreaks.com/topic/216423-php-on-the-command-line/
Share on other sites

It looks like your file is using windows style end of line characters instead of unix style.  Can your editor save the file with unix style end of line characters?

 

Maq, php-cgi itself gave him the first error message, it definitely exists :)

Thanks for the reply Maq,

 

In fact, "php-cgi" does INDEED exist in my /bin directory.  I've been specifically directed to this executable from my hosting provider when dealing with CLI.

 

A Google on the topic has brought up this:

 

"If you copy a file created or modified in Windows or DOS to a Linux/Unix file system, you sometimes find ^M characters at the end of each line."

 

This is indeed causing the problem I imagine.. as I develop on my home machine (Windows 7) and FTP files to my server (Fedora 9).  How would I get around this besides installing Fedora on my machine?  Am I going to have to abandon jEdit and my other favorite apps and just develop everything though SSH straight to my server?

 

This is the first time I've managed my own server and attempted to use PHP with CLI.  Any input is appreciated!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.