For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > January 2007 > how to pass commandline argument to C program from PHP code









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to pass commandline argument to C program from PHP code
balakrishnan.dinesh@gmail.com

2007-01-29, 3:59 am

hi frndz,

As we know that, we can pass command line agrument for C using
"scanf" commands, So as same as that, Is there any way to pass those
commandline arguments through php code to C and process them. If there
plz soon, or tel me any alternative for this

Rgrds
Dinesh..

lorento

2007-01-29, 3:59 am

Did you mean execute C program like in command line ?

<?php
exec ("yourprogram -n 1234");
?>

--
http://www.mastervb.net
http://www.theukmap.com
On Jan 29, 11:28 am, balakrishnan.din...@gmail.com wrote:
> hi frndz,
>
> As we know that, we can pass command line agrument for C using
> "scanf" commands, So as same as that, Is there any way to pass those
> commandline arguments through php code to C and process them. If there
> plz soon, or tel me any alternative for this
>
> Rgrds
> Dinesh..


Ruben van Engelenburg

2007-01-29, 7:58 am

balakrishnan.dinesh@gmail.com wrote:
> hi frndz,
>
> As we know that, we can pass command line agrument for C using
> "scanf" commands, So as same as that, Is there any way to pass those
> commandline arguments through php code to C and process them. If there
> plz soon, or tel me any alternative for this


Hi Dinesh,

I'm not sure what you mean, because in C you don't use scanf to retrieve
commandline arguments. You use scanf to get user-input. You use the argc
and argv arguments in main() to access commandline arguments.
In PHP you have similar variables: $argc and $argv. $argc holds the
number of arguments and $argv is the array containing the values.

HTH.
Ruben.
bob.chatman@gmail.com

2007-01-31, 3:59 am

On Jan 29, 2:21 am, Ruben van Engelenburg <nos...@nospam.com> wrote:
> balakrishnan.din...@gmail.com wrote:
>
>
> Hi Dinesh,
>
> I'm not sure what you mean, because in C you don't use scanf to retrieve
> commandline arguments. You use scanf to get user-input. You use the argc
> and argv arguments in main() to access commandline arguments.
> In PHP you have similar variables: $argc and $argv. $argc holds the
> number of arguments and $argv is the array containing the values.
>
> HTH.
> Ruben.


What he passed you is a command forwarded to the command line of your
server. its exactly the same as if you were to go:

yourprogram -n 1234

Your program would have ARGC = 2 and ARGV would be {"-n", "1234"}

it has nothing to do with the scanf or anything like that.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com