title: linux cat: No such file or directory
body: <p>I have a peculiar problem in Linux2.4, C and using gcc.</p>
  
  <p>There is a small program to retrieve information from a file using cat &amp; grep cmd.</p>
  
  <pre><code>#define tmpFile "/tmp/cli_tmp_file.txt"
  #define MAX_CMD 50
  
  void getRange()
  {
          char cmd[MAX_CMD+1];
  
          // remove the temp file first
          snprintf(cmd, MAX_CMD, "rm -f %s", tmpFile);
          system(cmd);
          // create temp file
          snprintf(cmd, MAX_CMD, "touch %s",tmpFile);
          system(cmd);
          // execute the command
          snprintf(cmd, MAX_CMD, "echo \"Range:Max val 500\" &gt; %s",tmpFile);
          system(cmd);
          // dump out the temp file so user could see
          snprintf(cmd, MAX_CMD, "cat %s|grep \"Range\"", tmpFile);
          system(cmd);
          // remove the temp file
          snprintf(cmd, MAX_CMD, "rm -f %s", tmpFile);
          system(cmd);
  }
  </code></pre>
  
  <p>when i execute this code, i get output as
  cat: /tmp/cli_tmp_file.txt: No such file or directory</p>
  
  <p>However, the file is created in the tmp folder with the contents</p>
  
  <pre><code># pwd
  /tmp
  # ls -l
  -rw-r--r--    1 root     root           68 Oct 10 12:54 cli_tmp_file.txt
  
  #more /tmp/cli_tmp_file.txt
  Range:Max val 500
  </code></pre>
  
  <p>On manual execution of the same cmd, it displays the intended output</p>
  
  <pre><code># cat /tmp/cli_tmp_file.txt|grep Range
  Range:Max val 500
  </code></pre>
  
  <p>Any help would be appreciated.
  Thanks in advance.</p>