title: getting the contents of the directory/client-server
body: <p>I need to create two applications - a client and a server that would exchange messages with each other .
  The server must process several commands submitted by the client, one of which is to receive the contents of the specified directory.  I kind of tried to do it, and it even works.(by the way, is it possible to do this without writing to a file?)But only this allows you to display the contents of the current directory. How can I do so that I can set not just <strong>ls</strong> to the console, but also the name of the directory (or the path to it) and I would be given the contents?That is, if we generalize, how can I set the name of a specific directory?</p>
  <p>And one more thing. I run the server in one terminal and the client in another. And when sending an <strong>ls</strong> command(message) to the server, I have the contents displayed both in the terminal with the client and the server.How can I make it appear only in the client, and this information is not displayed in the server?</p>
  <p>I will be very grateful for your help.</p>
  <pre><code>for(;;){
      recv_id=MsgReceive(channel_id,message, sizeof(message),NULL);
      printf( &quot;Receive message, recv_id=%d\n&quot;,recv_id);
      printf(&quot;Message is - %s\n&quot;,message);
      . . .
      else if (strstr(message, &quot;ls&quot;)!=0){
          FILE *f=popen(message,&quot;w&quot;);
          FILE *g;
          strcat(message, &quot;ls.txt&quot;);
          f=popen(message,&quot;w&quot;);
          pclose(f);
          g=fopen(&quot;ls.txt&quot;,&quot;r&quot;);
          strcpy(message,&quot;&quot;);
          while(feof(f)==0){
              fscanf(f,&quot;%s&quot;,&amp;in);
              strcat(message, in);
              strcat(message,&quot;\n&quot;);
          }
          fclose(g);
          printf(&quot;ls successfull\n&quot;);
      }
      . . .
  
      MsgReply(recv_id, EOK, message,sizeof(message)+1);  
  }
  </code></pre>
  <p><strong>upd</strong>:I seem to have figured out how to make it easier (yes, at the same time, the contents of the directory are not displayed on the server). But I still can't figure out how to handle this command not only for the current directory.</p>
  <pre><code>else if (strstr(message, &quot;ls&quot;)!=0){
      system(&quot;ls&gt;ls.txt&quot;);
      g=fopen(&quot;ls.txt&quot;,&quot;r&quot;);
      while(feof(g)==0){
          fscnaf(g,&quot;%s&quot;,&amp;in);
          strcat(message,in);
          strcat(message,&quot;\n&quot;);
      }
      fclose(g);
  }
  </code></pre>