if i run exec1 to execute a command such as ls; ls, then is there a way i can get a return value? If i am using pipes and the child process runs the exec1 line, how can the parent process know the return value of the result of exec1?
Do you mean exec? There is a shell comand in section 1 of the manual (man pages).
Or are you trying to get the C code to create a child process whith fork() and execl()?
I am guessing you want this:
Try the system() C call, then use the macros in sys/wait.h to get your return code.
if i run exec1 to execute a command such as ls; ls, then is there a way i can get a return value?
I'm guessing you mean execl.
If it finds the program at all, the execl call never returns because execl tells your program to replace itself with the program you created. So naturally it can't return anything directly.
Quote:
If i am using pipes and the child process runs the exec1 line, how can the parent process know the return value of the result of exec1?
Using the waitpid() call you can get a process' return statistics, like
You should always wait() for your children, if not immediately then some time or other, since they can't truly quit until you do -- just hang around taking up space in the process table.
so if i have a command and i want a child process to execute it and return the return value to the parent process, can i use:
will return_value get the return value of the command ls; ls ?
the man of system says:
system() executes a command specified in command by calling /bin/sh -c
command, and returns after the command has been completed. During exeâ
cution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT
will be ignored.
i dont understand how to return after the command has been completed...
will return_value get the return value of the command ls; ls ?
no; that ends up as part of the status variable, which you can get with WEXITSTATUS(status).
I don't know what you expected to read from fd[0] after you closed it anyway.
fileno(stdin) is redundant. stdin is always 0. Use STDIN_FILENO (from unistd.h) if you want to be symbolic.
Quote:
the man of system says:
system() executes a command specified in command by calling /bin/sh -c
command, and returns after the command has been completed. During execution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT
will be ignored.
i dont understand how to return after the command has been completed...
system() does so by itself.
Last edited by Corona688; 03-13-2011 at 07:56 PM..
It might, if the amount of data is small enough. But the child might end up waiting forever for you to read the pipes, so, if you're not going to use the data the child printed to the pipe, close() them before you wait().
Hi Folks,
I have a file name abc.xml in my windows machine at the location c:\ytr\abc.xml
which I want to place at the unix box machine inside cde directory.. at the following location that is /opt/app/cde/
now the credentials of unix box are
abc345 -->(dummyid)
ftyiu88--->(dummy passwd)
... (4 Replies)
I'm trying to write a bash script called YN that looks like the following
YN "Specify a question" "doThis" "doThat"
where "doThis" will be executed if the answer is "y", otherwise "doThat".
For example
YN "Do you want to list the file dog?" "ls -al dog" ""
Here's my attempt... (3 Replies)
Hi all,
I wish to know whether Unix can access window's file in Unix's terminal?
Apart from that, how to copy files or share files between Window and Unix? I get to know of secure copy, however, my company's Unix does not support the feature of secure copy? Any other method for me to share/... (5 Replies)
I am going through the Unix Made Easy second edition book by John Muster. So far it's been very informative and I can tell it may be a bit out of date.
In one of the exercises it talks about the "sort" command and using it to sort column's of data etc. The "sort" command has changed a bit and... (1 Reply)
Hi,
Well my title isn't very clear I think. So to understand my goal:
I have a script "test1"
#!/bin/bash
xvkbd -text blabla
with xbindkeys, I bind F5 key in order it runs my test1 script
So when I press F5, test1 runs.
I'm under Emacs/Vi and I press F5 in order to have "blabla" be... (0 Replies)
Hi ,
I have a piece of code ...wherein I need to assign the following ...
1) A command line argument to a variable
e.g origCount=ARGV
2) A unix command to a variable
e.g result=`wc -l testFile.txt`
in my awk shell script
When I do this :
print "origCount" origCount --> I get the... (0 Replies)
Hello,
I have problem in writing the shell script involving MPE command STREAM related to HP-UX and Unix command. Script is
sh "nlshCMD 'STREAM <job name1>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name2>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name3>' |... (1 Reply)
Hello,
I have problem in writing the shell script involving MPE command STREAM related to HP-UX and Unix command. Script is
sh "nlshCMD 'STREAM <job name1>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name2>' | 'SHOWJOB' | grep $HPJOBNUM"
sh "nlshCMD 'STREAM <job name3>' |... (0 Replies)
hi all. thanks for looking
i am doing some homework.
one question is that when type
wc
and then how to tell the program that we have finished entering data?
also
why do some operating systems report 22 as the number of bytes in the file above, while others only 20?
thanks so much,... (1 Reply)