想使用exec()函数从php运行c程序

想使用exec()函数从php运行c程序

问题描述:

i'm trying to run one c executable file using php exec().

When c contains a simple program like print hello. I'm using

exec('./print.out')

It's working fine. But when I need to pass a argument to my c program I'm using

exec('./arugment.out -n 1234')

It is not working. Can any body tell me how to pass arugment using exec to c program.

我正在尝试使用php exec() code>运行一个c可执行文件。

当c包含一个简单的程序,如 print hello code>。 我正在使用 p>

  exec('./ print.out')
  code>  pre> 
 
 

它工作正常。 但是,当我需要将参数传递给我的c程序时,我正在使用 p>

  exec('。/ arugment.out -n 1234')
  code>  
 
 

它不起作用。 任何机构都可以告诉我如何使用 exec code>传递给c程序。 p> div>

From taking a look at the php documentation, it appears that exec treats arguments a bit oddly. You could try doing

exec("./argument.out '-n 1234'")

to prevent it from mangling them (it normally separates them all on space, which might be what's messing it up).