Note that there are some explanatory texts on larger screens.

plurals
  1. POfopen() stream to popen() for progress bar/controll - but how to get stdout of popen()?
    primarykey
    data
    text
    <p>I'm trying to write simple c function which would give me possibility to see progress of data transfer from one stream to other stream and display it on my char LCD.</p> <p>I manage to transfer the data and indicate the progress but how to get result of the piping?</p> <p>So basically i want to do in c corresponds to shell command:</p> <pre><code>/home/image.img | md5sum &gt; result </code></pre> <p>The problem i have i with the stdout. I would like to get it to a char * result.</p> <p>In other words the md5sum returns a string on the screen like this "5193fd9ebfa30bcb914e7af4760deb15" but i would like to get it to my char * result for further usage in the function.</p> <pre><code>FILE *in_stream, *out_stream; #define TRANSFER_BLOCK_SIZE 1048576 //one MB int n=0; int i=0; long int input_size=0; unsigned char buffer[TRANSFER_BLOCK_SIZE]; if((out_stream=popen("md5sum","w"))==NULL) { perror(output_pipe_name); return 1; } if((in_stream=fopen("/home/gregorek/image.img","r"))==NULL) { perror(input_file_name); return 1; } //check total size of the input file fseek(in_stream,0,SEEK_END); input_size=(ftell(in_stream)/TRANSFER_BLOCK_SIZE)+1; fseek(in_stream,0,SEEK_SET); // do { i++; memset(buffer,'\0',TRANSFER_BLOCK_SIZE); n=fread(buffer,sizeof(unsigned char),TRANSFER_BLOCK_SIZE,in_stream); lcd_display(i); //this is my progress indicator fwrite(buffer,sizeof(unsigned char),n,out_stream); } while(!feof(in_stream)); fclose(in_stream); pclose(out_stream); </code></pre> <p>return 0;<br> }</p> <p>thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload