[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1240
  • Last Modified:

php exec() command does not work on my php server

I am trying to run any command via php with no luck. I am running on Windows XP Pro, Apache and PHP 5.  Here is the command I use from the Windows command prompt.

php exec('dir')

I get an error: Cannot open input file exec('dir')

I tried full path, double quotes and tried with the system() command instead, but always same error. I have done this before, not sure why it is not working.
PHP works fine with my webpages, no errors at all.
0
advcom
Asked:
advcom
  • 3
  • 2
  • 2
  • +2
2 Solutions
 
Paul SCommented:
It must be a problem in your php.ini file. did you check all the settings? what is the output of php_info(); look like on that server?
0
 
Dave BaldwinFixer of ProblemsCommented:
I get the same error on my computer and it doesn't work even when I put it in a file.  Just does nothing.
0
 
Hugh McCurdyCommented:
The command is phpinfo() on my computer.

I suggest you look at the Safe Mode section of your php.ini file.  Of note

; When safe_mode is on, only executables located in the safe_mode_exec_dir
; will be allowed to be executed via the exec family of functions.


0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
Ray PaseurCommented:
When exec() is the answer, usually we are asking the wrong question.  Maybe if you can step back from the technical details and tell us what you want to achieve we will be able to give you a good solution.  There are many built-in PHP functions for working on the file system.
0
 
Hugh McCurdyCommented:
Excellent point Ray.  Advcom, please share the purpose of trying to use exec.  

Hugh
0
 
advcomAuthor Commented:
I wrote a ticket/invoice system for my computer repair business and it works fine. Sometimes techs need to call in to the office and check for new appointments. I added a button on each ticket that can be clicked and it will send a text to the assigned tech with all the info. I discovered that when I send a text with built-in sendmail, Sprint ignores it, but it works fine with gmail. So I downloaded a simple utility called SendEmail and use Gmail smtp server and Sprint accepts it and forwards the text correctly. I figured I would just have php call SendEmail.exe with the ticket info and everything would be great, but I cannot get exec() to work. I have used this before for on the fly picture resizing, so I am pretty sure I am doing this correctly. I can give a link to my phpinfo if needed.
0
 
Ray PaseurCommented:
Have you looked into using Twilio to send text messages?  Very economical and they have a really easy-to-use interface.
http://www.twilio.com/
0
 
Dave BaldwinFixer of ProblemsCommented:
The first thing is you're doing it wrong.  Typing "php exec('dir')" at the command prompt runs PHP and hands it "exec('dir')" as a filename to run which of course, it isn't.  That's not a PHP thing, it's standard operation with all the operating systems that I know of.  PHP command line operation here: http://www.php.net/manual/en/features.commandline.php
0
 
Hugh McCurdyCommented:
Well, Dave, there's that.

Advcom, put this in a file and see if it work for you


<?php
echo exec ( "dir" ) . PHP_EOL;
?>

Open in new window


0
 
advcomAuthor Commented:
I think I was half asleep when I was testing. I orginally did as hmccurdy did, but I had a php error in my code before that point that was causing it to fail. Anyways, it works fine now and I can send my info via text as I wanted.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now