title: Python cron subprocess Popen throwing OSError [Errno 2], works when executed manually
body: <p>I am trying to automate a Python script to continuously capture and write network packets to files.  The script relies heavily on the use of Wireshark's dumpcap CLI command, and uses the subprocess Popen module to run the command in a shell.  During normal execution, the script creates a new directory and begins capturing network data to that new directory.  The script runs to completion when executed manually on the command line, however, when I have cron execute the job the script terminates before the capture begins with the following error:</p>
  <pre><code>Traceback (most recent call last):
      File &quot;./netcapture.py&quot;, line 19, in &lt;module&gt;
          dumpcap = subprocess.Popen(['dumpcap', '-i', '3', '-a', 'duration:30', '-b', 'duration:10', '-w', filepath], cwd=r'/var/tmp/traces/')
      File &quot;/usr/lib64/python2.6/subprocess.py&quot;, line 642, in __init__ errread, errwrite)
      File &quot;/usr/lib64/python2.6/subprocess.py&quot;, line 1238, in __execute_child raise child_exception
  OSError: [Errno 2] No such file or directory
  </code></pre>
  <p>the filepath variable is</p>
  <pre><code>netdata_02_24_2021/trace.pcap
  </code></pre>
  <p>which is the name of the newly created directory and a filename &amp; type for dumpcap to write the network data to.  I am running this script with Python 2.6 on RHEL 6 for reference.  The cron job syntax is as follows:</p>
  <pre><code>0 0 * * * cd /var/tmp/traces/ &amp;&amp; python ./netcapture.py &amp;
  </code></pre>
  <p>Things I know:</p>
  <ul>
  <li>cron is able to find and execute the script</li>
  <li>the current working directory that the script executes in is correct</li>
  <li>subprocess.Popen works when executed by cron, as it is used prior to the error being thrown to successfully make a</li>
  </ul>
  <pre><code>mkdir -p netdata_02_24_2021
  </code></pre>
  <p>call in the current working directory</p>
  <ul>
  <li>the pathing is correct for the capture write.  I am able to execute this script manually and it recognizes the new directory and writes to it</li>
  </ul>
  <p>Things I have tried:</p>
  <ul>
  <li>providing the full path for all directories</li>
  <li>switching the subprocess.Popen() calls to subprocess.check_call() calls</li>
  <li>using the shell=True syntax in my subprocess.Popen() calls</li>
  </ul>
  <p>At this point, I'm not sure what could be causing this execution issue with cron.  Any help would be greatly appreciated.</p>