Passing cmd line variables from a php file
Is this possible from a PHP file
$var1 = 1
$var2 = 2
$output = `./a.out $var1 $var2 `
or
$output = exec(./a.out $var1 $var2);
consider a.out to be the C program executable.
Where $var1 and $var2 are passed as command line arguements? If this is not possible, is there any other easier way of passing php variables as input to my C program executable?
Tha开发者_Python百科nks!
Yes, that is possible.
Since you are asking for potential alternatives, you could consider passing the arguments as environment variables instead (which might be insignificantly easier to access in your C binary):
exec("VAR1='$var1' VAR2='$var2' ./a.out");
Sure, it would work. The syntax however is little different:
$output = exec("./a.out $var1 $var2");
Php would put the actual values into the string, so a.out
would execute with arguments 1 2
.
精彩评论