Unix Programming - system() function usage

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > April 2006 > system() function usage





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 system() function usage
nandu

2006-04-27, 7:56 am

Hello Guys,
I have a doubt in system() function. I need to implement
the certain command line arguements in a program.
For Example

if I type "dnaml" at command line and press enter then it will ask me
to enter 'Y' and if I press enter it will generate some files.
So here I used


system("dnaml")


function and I am confused how to provide 'Y' without typing in
command line.
Any help will greatly be appreciated.


Thank You
Nandini

Sreekanth

2006-04-27, 7:56 am

nandu wrote:
> Hello Guys,
> I have a doubt in system() function. I need to implement
> the certain command line arguements in a program.
> For Example
>
> if I type "dnaml" at command line and press enter then it will ask me
> to enter 'Y' and if I press enter it will generate some files.
> So here I used
>
>
> system("dnaml")



You can try using:

fork and execv() function calls.

Please check the man pages for the usage of same.

Also u need a wait to capture the process exit status. If your program
requires command Line argument. But as per your statement you have
mentioned it as a program prompt.

Now you can also pass on arguments very crudely as in

system("daml y");

where u construct the string which u pass to system.

for further references please take a look at following link:

http://www.cs.cf.ac.uk/Dave/C/node22.html

>
>
> function and I am confused how to provide 'Y' without typing in
> command line.
> Any help will greatly be appreciated.
>
>
> Thank You
> Nandini


Gordon Burditt

2006-04-27, 7:56 am

> I have a doubt in system() function. I need to implement
>the certain command line arguements in a program.
>For Example
>
>if I type "dnaml" at command line and press enter then it will ask me
>to enter 'Y' and if I press enter it will generate some files.


If you wish to provide command line arguments, put them on the
command line when you call, for example, system("dnaml y"). If the
command line is not a constant, construct the command line in a
string (sprintf() is often helpful here, but there are many other
ways of accomplishing the same thing).

If you need to provide interactive input (not command line arguments),
the command being run will get it from its inputs: typically stdin,
although it's not unheard of for commands to *READ* stderr ("more"
command) or /dev/tty (programs using getpass(), like "su" and
"passwd") passed to it when the command was run. If you don't use
shell redirection, this is stdin at the time of the system() call.

If you need to provide answers to prompts from the program, consider
using popen(command, "w") instead of system(). Or you could use
system() with input redirection and a file with the answers in it.

>So here I used
>
>
>system("dnaml")
>
>
> function and I am confused how to provide 'Y' without typing in
>command line.
>Any help will greatly be appreciated.


Gordon L. Burditt
Fred Kleinschmidt

2006-04-27, 7:56 am


"nandu" <nnandini8@gmail.com> wrote in message
news:1145556654.248089.307020@e56g2000cwe.googlegroups.com...
> Hello Guys,
> I have a doubt in system() function. I need to implement
> the certain command line arguements in a program.
> For Example
>
> if I type "dnaml" at command line and press enter then it will ask me
> to enter 'Y' and if I press enter it will generate some files.
> So here I used
>
>
> system("dnaml")
>
>
> function and I am confused how to provide 'Y' without typing in
> command line.
> Any help will greatly be appreciated.
>
>
> Thank You
> Nandini
>

system( "echo Y | dnaml" );
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com