read input-process-output

Thread Tools Search this Thread
Top Forums Programming read input-process-output
# 1  
Old 10-04-2009
read input-process-output

Can you help me ?
I want to write a program ,which can open a input file (input.txt) and run as child process ,then write to output file (output.txt).......
c code:
  1. char inFile[1024]="input.txt";
  2. char outFile[1024]="output.txt";
  3. int main(int argc, char **argv)
  4. {
  5.   pid_t pid=1;
  6.   int no=0;           // no. of command
  7.   char command[1024]; // contain each line of input file
  8.   ...........
  9.  while (pid && fgets(command,1023,iFile)!=NULL)
  10. {
  11.         if (pid==0){
  13.       //TODO: Child process
  14.       //      Run command and write output to file
  15.       //      Child process should sleep 1 second to wait parent prcess
  16.       //        to finish writing to output file
  18.     else if (pid>0)
  19.   {
  21.       //TODO: Parent process
  22.       //      Write the no. of command to file
  23.       //      Wait child process to finish
  25.     }
# 2  
Old 10-04-2009
What help you want ?

1. You have a good amount of notes on what to do, do it.

2. Try out, if you have certain issues, come back and get advice on that.

3. Place the code in proper code tags, for better visibility.
# 3  
Old 10-04-2009
In child process :
system(command); //Run command

But I don't know how to write to output file ?
# 4  
Old 10-05-2009
If it is appropriate, use like the following.,
system("/bin/ls >> /tmp/lsout");

  • system -- function call,
  • /bin/ls -- absolute path of command,
  • >> output redirection
  • /tmp/lsout -- absolute path of file to capture output.
# 5  
Old 10-05-2009
you can simply use fork() and in child process use fwrite(command, output.txt). After fork, child and parent share open files.

Though It will be better if you post complete code and exactly what you wanted to do?
# 6  
Old 10-11-2009
Can I use : system("%s >> %s",command,outFile) ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read input write multply output with creteria

Hi All Please Help Read input write multply output with creteria Exemple i have file abc 111 444 abc 111 444 def 111 444 def111 444 bbb 111 444 bbb 111 444 i would need write 3 files pos 1-3 is the Criteria output would be file1 contains abc file2 def file3 bbb ... (3 Replies)
Discussion started by: tonyk334
3 Replies

2. Shell Programming and Scripting

ksh - Read input from file and output CSV i same row

Hello I have the following output and want the output to look: FROM: GigabitEthernet0/0 is up, line protocol is up 1 input errors, 0 CRC, 0 frame, 1 overrun, 0 ignored 275 output errors, 0 collisions, 3 interface resets GigabitEthernet0/1 is up, line protocol is up 0... (4 Replies)
Discussion started by: JayJay2018
4 Replies

3. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

4. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies

5. Shell Programming and Scripting

Read file from input and redirect to output file

Hi , i am having an file which contains 5 file_name data, i need to read the file name and will perform certain operation and generate out file names with named as 5 individual file_names for eg: file.txt contains file_name1.txt|hai file_name2.txt|bye file_name3.txt|how... (3 Replies)
Discussion started by: rohit_shinez
3 Replies

6. Shell Programming and Scripting

Print output and read input on same line

How do I print output and read input on the same line in ksh? echo Hello, what is your name? read name (1 Reply)
Discussion started by: robin_simple
1 Replies

7. Shell Programming and Scripting

Read input and output redirection filename within a script

Hello everyone, My requirement is that within a script I need to construct the command line exactly that it was invoked with. For example : sh arg1 arg2 arg3 < input.txt > output.txt Now within, I construct a file which has these contents " sh arg1 arg2 arg3 < input.txt >... (8 Replies)
Discussion started by: hedonist12
8 Replies

8. Shell Programming and Scripting

Script to read input and output files and child scripts

I have a directory where i have *.sas; *.pl;*.sh and *.c scripts I need to find out what are the child scripts and input output files for each script: say I have a shell script which calls a perl script and a sas script: In my first line I want I a) the parent script name; b) the... (1 Reply)
Discussion started by: ramky79
1 Replies

9. Shell Programming and Scripting

How to read the input from a file in background process?

Hi I have a script to run some other scripts automatically. But while running the script it should take the input value from a text file instead of taking from the keyboard. Please find last two lines of the script below. Here ans should be taken from a text file ineerly without displaying this... (1 Reply)
Discussion started by: shirdi
1 Replies

10. Shell Programming and Scripting

Read from file > process > output to file

Hi all, OK, I am totally new to shell scripting as I just started today. All I want from shell scripting is something very basic, and I've been searching for tutorials on "processing files" and I could not find a suitable one for my level. I want to read two columns from a data file, one raw... (3 Replies)
Discussion started by: Lorna
3 Replies
Login or Register to Ask a Question