Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In real shells (meaning, not sea shells - I mean, not in C Shell or its derivatives), then:</p> <pre><code>program arg1 arg2 &gt;/tmp/log.file 2&gt;&amp;1 </code></pre> <p>This runs program with the given arguments, and redirects the stdout to /tmp/log.file; the notation (<del>hieroglyph</del>) '<code>2&gt;&amp;1</code>' at the end sends stderr (file descriptor 2) to the same place that stdout (file descriptor 1) is going. Note that the sequence of operations is important; if you reverse them, then standard error will go to where standard output was going, and then standard output (but not standard error) will be redirected to the file.</p> <p>The choice of file name shown is abysmal for numerous reasons - you should allow the user to choose the directory, and probably should include the process ID or time stamp in the file name.</p> <pre><code>LOG=${TMPDIR:-/tmp}/log.$$.$(date +%Y%m%d-%H%M%S) program arg1 arg2 &gt;$LOG 2&gt;&amp;1 </code></pre> <p>In C++, you can use the <code>system()</code> function (inherited from C) to run processes. If you need to know the file name in the C++ program (plausible), then generate the name in the program (<code>strftime()</code> is your friend) and create the command string with that file name. (Strictly, you also need <code>getenv()</code> to get $TMPDIR, and the POSIX function <code>getpid()</code> to get the process ID, and then you can simulate the two-line shell script (though the PID used would be of the C++ program, not the launched shell).</p> <p>You could instead use the POSIX <code>popen()</code> function; you'd have to include the '<code>2&gt;&amp;1</code>' notation in the command string that you create to send the standard error of the command to the same place as standard output goes, but you would not need a temporary file:</p> <pre><code>FILE *pp = popen("program arg1 arg2 2&gt;&amp;1", "r"); </code></pre> <p>You can then read off the file stream. I'm not sure whether there's a clean way to map a C file stream into a C++ istream; there probably is.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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