nethnet Posted October 20, 2010 Share Posted October 20, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/216423-php-on-the-command-line/ Share on other sites More sharing options...
Maq Posted October 20, 2010 Share Posted October 20, 2010 It's cause php-cgi does not exist in your bin directory. Just make sure the extension is .php and use <?php ?> tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/216423-php-on-the-command-line/#findComment-1124653 Share on other sites More sharing options...
DavidAM Posted October 20, 2010 Share Posted October 20, 2010 ^M is a carriage return. You need to use an editor that will save the file in "unix" format - line feeds only - no carriage returns. Quote Link to comment https://forums.phpfreaks.com/topic/216423-php-on-the-command-line/#findComment-1124654 Share on other sites More sharing options...
btherl Posted October 20, 2010 Share Posted October 20, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/216423-php-on-the-command-line/#findComment-1124655 Share on other sites More sharing options...
nethnet Posted October 20, 2010 Author Share Posted October 20, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/216423-php-on-the-command-line/#findComment-1124657 Share on other sites More sharing options...
Maq Posted October 20, 2010 Share Posted October 20, 2010 Silly me Quote Link to comment https://forums.phpfreaks.com/topic/216423-php-on-the-command-line/#findComment-1124659 Share on other sites More sharing options...
nethnet Posted October 20, 2010 Author Share Posted October 20, 2010 Ah, I didn't see those new replies. I imagine jEdit would support that feature, seeing as how it's one of the best development text editors? I'll check into it, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/216423-php-on-the-command-line/#findComment-1124660 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.