tags:

views:

164

answers:

2

hi 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.

+4  A: 

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).

Kitsune
So if I'd like to pass 2 arguments I should do `exec("./argument.out '-n 1234 -o 5678'")` or `exec("./argument.out '-n 1234' '-o 5678'")` ?
hsz
when i m trying to run exec("./a.out '-n 1234'") i m getting error:bash: syntax error near unexpected token `"./a.out '-n 1234'"'
Abhimanyu
A: 

I did try with the way Kitsune suggested, but no success.. program became unresponsive.. Below is my part of code echo $ssh->exec("/xxx/xxx.xxx.xxx/xxx/xxx/xxx/xxx/./demo '2 3'"); where demo is a simple program which computes addition of two numbers. In this example the two numbers are 2 and 3 which are provided by the user. Any ideas to provide arguments for exec() function?

Thanks in advance,

Superted