Execute cmd command with exec returns to null

Source: Internet
Author: User
I put the pdf2swf.exe of Swftools in the Web site root directory in PHP using the EXEC function to execute commands
$cmd = "c:/php/www/pdf2swf c:/php/www/upload/1.pdf c:/php/www/upload/1.swf"
EXEC ($cmd);
I directly paste this code into the command line execution is correct PHP so call but unsuccessful exec after two parameters plus the second parameter is an array (); The third one is 1, unsuccessful and then modified I am directly in the directory with a php file written in the exec (pdf2swf 1. PDF 1.swf) What's the reason for the success of this implementation?
Note: The above code i in my local test completely through, put on the server is the above error, are windows2003 on-line IIS native Apache


Reply to discussion (solution)

Read the manual first.

EXEC () The second parameter is the information returned by the screen, each of which behaves as a unit, constituting an array

Read the manual first.

EXEC () The second parameter is the information returned by the screen, each of which behaves as a unit, constituting an array


Well, this array is empty. There is no information on the upper screen. I paste the command directly into the command line and execute it correctly.

Because you manually open the command line, is to undertake the system environment, so you can directly run the file
But with PHP execution, and can not undertake the system environment, so you still need to specify executable files (EXE, etc.)

This should be a user permissions issue
Directly in the directory with a PHP file can be successful
But obviously not web-run, because you can't put the root of the site on the root of the C-drive

Suggestions:
Move the Site directory to the D drive and grant the anonymous user the right to execute
Do not put the site on the C drive to prevent accidental damage to system files, while the system crashes, disaster recovery of a much smaller amount of work

Because you manually open the command line, is to undertake the system environment, so you can directly run the file
But with PHP execution, and can not undertake the system environment, so you still need to specify executable files (EXE, etc.)



I added the pdf2swf to the back of the. exe or can't execute I tried ipconfig this command no problem maybe it should still be the path problem I have written the absolute path to ask eldest brother I is not the path where there is a problem?

$MCD = "D:\JGY\JGY_WEB\JGY_PHP\install_package\app\pdf2swf.exe D:\JGY\JGY_WEB\JGY_PHP\install_package\uploadfile\ 2012\1222\20121222110539946.pdf D:\JGY\JGY_WEB\JGY_PHP\install_package\uploadfile\2012\1222\20121222110539946. SwF
EXEC ($cmd, $out);

This is my cmd command longer please enlighten

This should be a user permissions issue
Directly in the directory with a PHP file can be successful
But obviously not web-run, because you can't put the root of the site on the root of the C-drive

Suggestions:
Move the Site directory to the D drive and grant the anonymous user the right to execute
Do not put the site on the C drive to prevent accidental damage to system files, while the system crashes, disaster recovery of a much smaller amount of work


Well moderator big I was put in the site root directory is not C packing directory
D:\JGY\JGY_WEB\JGY_PHP\install_package This is the root directory of my website
I'm going to put Pdf2swf.exe under this and put a 1.pdf and build a index.php.
The code inside is directly exec (pdf2swf 1.pdf 1.swf)
This can be successful.

Then the following code:
$MCD = "D:\JGY\JGY_WEB\JGY_PHP\install_package\app\pdf2swf.exe D:\JGY\JGY_WEB\JGY_PHP\install_package\uploadfile\ 2012\1222\20121222110539946.pdf D:\JGY\JGY_WEB\JGY_PHP\install_package\uploadfile\2012\1222\20121222110539946. SwF
Path comparison deep three parameters have spaces in the middle, but this is not going to be.

$mcd
$cmd
I see two different variable names.

$mcd
$cmd
I see two different variable names.


Well, this is the one I just knocked on. I was in IE echo out of the cmd command
D:\JGY\JGY_WEB\JGY_PHP\install_package\app\pdf2swf.exe D:\JGY\JGY_WEB\JGY_PHP\install_package\uploadfile\2012\ 1222\20121222110539946.pdf D:\JGY\JGY_WEB\JGY_PHP\install_package\uploadfile\2012\1222\20121222110539946.swf
That's the path.

Try single quotes again ... Don't want to do this, just try it.

$cmd = "c:/php/www/pdf2swf c:/php/www/upload/1.pdf c:/php/www/upload/1.swf"
EXEC ($cmd);
This is the code in your post.
If you provide the information, how can you get the real results?

$cmd = "c:/php/www/pdf2swf c:/php/www/upload/1.pdf c:/php/www/upload/1.swf"
EXEC ($cmd);
This is the code in your post.
If you provide the information, how can you get the real results?


I'm sorry, I'm sorry, because my address was in the program. I'm not going to have to write a direct URL like this. $cms this variable is the path
D:\JGY\JGY_WEB\JGY_PHP\install_package\app\pdf2swf.exe D:\JGY\JGY_WEB\JGY_PHP\install_package\uploadfile\2012\ 1222\20121222110539946.pdf D:\JGY\JGY_WEB\JGY_PHP\install_package\uploadfile\2012\1222\20121222110539946.swf
Excuse me the moderator adult again to analyze is not the problem of IIS? I was on the local Apache test is normal IIS looked at all the users have read and write Execute permissions

The first thing to address is the issue of permissions
If the directive executes correctly in the command line or batch, then the problem is "permissions"
Of course, you're not going to disable the EXEC function.

I also encountered the same situation, but my command could succeed, but there was no return value. I don't know where the problem is.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.