i dont see where in your version are u recording the amount of bytes written
It happens here:
'bytes' gets set to the number of bytes it was able to read, or 0 on EOF, see 'man 2 read'.
Quote:
this line reads
bytes=read(fd[0], pipeout, 512);
and it reads 512 bytes which i think is more than needed, how do i know the amount written from execl?
512 is just a maximum. It reads as much as it can up to the maximum and tells you where it stopped. You don't need to know the exact amount the child wrote -- you can read its output in as big or as small chunks as you want, though you don't always get what you asked for. Check the return value of read() to find out what you actually got.
You may not get the exact amount that the child wrote, by the way, since the pipe is also a buffer. The child could do ten writes of 10 bytes and you get one read of 100 bytes; up to a few kilobytes of data may pile up in the pipe before it actually lets anything through. It flushes when the writing end closes, which is why you're still able to get less (and why you need to close the writing end if you're not using it.)
Last edited by Corona688; 03-14-2011 at 06:59 PM..
so to correctly output the result i need this command?
printf(pipeout, bytes);
For the third time, don't use printf. printf expects NULL-terminated C strings and raw data read from a file is almost never a NULL-terminated C string.
To output properly, use the code I gave you:
Quote:
Originally Posted by Corona688
This is not pseudocode. read() and write() are system calls. All of that is necessary, including the loop, to properly handle the program's output, otherwise it might stop before the program's actually finished.
when i run the program using something like
./my_prog ls; ls; ls
argc is only equal to 2, and not 4, why is this? I want the input ls; ls; ls to be accessed in my program...
; is a special character to the shell. a ; b ; c means "run a, then run b, then run c". If you want to feed raw ;'s into something you have to quote them../my_prog ls';' ls';' ls The shell will strip off the quotes before it calls ./my_prog
i tried the command was cd abc';' ls
but i am still in the same directory, is this because the child process ran the exec1 command? if so then if i reverse it so the parent does what the child did and child does what the parent did, then will the cd abc';' ls actually move it to the abc directory?
i tried the command was cd abc';' ls
but i am still in the same directory, is this because the child process ran the exec1 command?
execl. Not exec1, execl. ell ell ell.
Yes, the child is independent, so changing directory in it didn't change it in the parent.
Quote:
if so then if i reverse it so the parent does what the child did and child does what the parent did, then will the cd abc';' ls actually move it to the abc directory?
I have no idea what you're asking now. Why don't you try it?
If you change directory in the parent, then create a child, the child will have the same current directory as the parent, being a clone in all respects.
Last edited by Corona688; 03-15-2011 at 12:59 AM..
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)