简体   繁体   English

在php上执行命令exec的问题

[英]Issue with the command exec on php

I've an issue while using exec on php, maybe I didn't understand how it works. 我在php上使用exec时遇到问题,也许我不明白它是如何工作的。

The problem is: I wanna execute a binary file named 'test.exe'. 问题是:我想执行一个名为“ test.exe”的二进制文件。 That program takes data from an input file 'input.xml' and create an new file 'output.xml' with some modification on those data. 该程序从输入文件“ input.xml”中获取数据,并创建一个新文件“ output.xml”,并对这些数据进行一些修改。

The below command line works perfectly on windows cmd : 下面的命令行在Windows cmd上运行良好:

>cd C:\Test
>test.exe C:\XML\example.xml C:\XML\example.out.xml

But a php script like this : 但是这样的PHP脚本:

exec('C://Test//test.exe C://XML//example.xml C://XML//example.out.xml');

Doesn't work like suspected; 不像怀疑的那样工作;

Each time I get beside the empty generated file example.out.xml another file named gmon.out. 每次我在生成的空文件example.out.xml旁边找到另一个名为gmon.out的文件。

I don't know what kind of file it is. 我不知道它是哪种文件。 Is it possible that this file will be the source of my problem? 此文件是否可能是我的问题的根源?

Any idea? 任何想法?

You're using the wrong slash, you should be using a double backslash (one to be printed, and another to escape it). 您使用了错误的斜杠,应该使用双反斜杠(一个要打印,另一个要转义)。 Using // will be literally translated to // so PHP will try to find C://Test//test.exe and fail. 使用//将被字面翻译为//因此PHP将尝试查找C://Test//test.exe并失败。

The corrected syntax would be either 更正的语法将是

exec('C:\\Test\\test.exe C:\\XML\\example.xml C:\\XML\\example.out.xml');

or 要么

exec('C:/Test/test.exe C:/XML/example.xml C:/XML/example.out.xml');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM