<div dir="ltr">Hi,<div><br></div><div>Thanks for the quick response :-)<br><div><br></div><div>I&#39;m already in the process of changing my program because I&#39;ll get the change faster, but some of the things I want to run using this method are not under my control and I&#39;ll need another solution for those.  I guess I can work my way around this using a shell script, but then I have to maintain a pair of them (Linux and Windows) in some cases.  Maybe I&#39;ll end up writing a Python wrapper instead, but it&#39;s still boilerplate that I would prefer avoiding.</div><div><br></div><div>Concerning shell redirection... I would be ready to live with explicit &quot;stdout=...&quot; and &quot;stderr=...&quot; options in my testenv sections.  I simply said I tried it and it didn&#39;t work, not that I really want this built into Tox.  Anyways, I&#39;m pretty confident that I can hack up a way to parse the string to extract the redirection operators and then use a safer technique (can&#39;t be that hard), but I&#39;m wondering what the security concern is.  The subprocess module warns against using this technique to run a command that comes from untrusted user input, which I doubt is the case here.  Besides, if I work around this issue by delegating the task to a shell script, how am I any safer?</div><div><br></div><div>André</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 13, 2016 at 4:32 PM, Ian Cordasco <span dir="ltr">&lt;<a href="mailto:graffatcolmingov@gmail.com" target="_blank">graffatcolmingov@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So, let&#39;s look at how we might take a command from tox and use<br>
subprocess to run it:<br>
<br>
import shlex<br>
import subprocess<br>
<br>
command_string = &#39;echo &quot;foo&quot; &gt; ex.txt&#39;<br>
p = subprocess.Popen(shlex.split(command_string),<br>
stdout=subprocess.PIPE, stderr=subprocess.PIPE)<br>
(out, _) = p.communicate()<br>
print(out)<br>
<br>
What you&#39;ll see printed is:<br>
<br>
&quot;foo&quot; &gt; ex.txt<br>
<br>
In other words, subprocess is limited to being secure by default and<br>
doesn&#39;t allow shell redirection for good reasons. What you can do<br>
instead is write a tiny bash/bat script that does the redirection for<br>
you and then call that. Alternatively you could teach the program to<br>
put its output into a file. (Flake8, for example, added --output-file<br>
for this exact use case quite a while back.)<br>
<br>
In other words, to add redirection into tox you have to teach it about<br>
shell semantics and potentially weaken its security stance.<br>
<div><div class="h5"><br>
<br>
<br>
On Mon, Jun 13, 2016 at 3:14 PM, André Caron &lt;<a href="mailto:andre.l.caron@gmail.com">andre.l.caron@gmail.com</a>&gt; wrote:<br>
&gt; Thanks, I&#39;ll take a crack at that!<br>
&gt;<br>
&gt; I hadn&#39;t noticed before, but by fiddling around a bit, but it looks like:<br>
&gt; - Tox merges stdout and stderr of the commands into Tox&#39;s stdout.<br>
&gt; - shell redirection inside the commands doesn&#39;t work (at least on Windows).<br>
&gt;<br>
&gt; Intuitively, I would expect stderr from my commands to be forwarded to<br>
&gt; stderr.  Since this is not the case, I was willing to fall back onto<br>
&gt; redirecting stdout from my process directly to a file, but then I can&#39;t do<br>
&gt; that inside my Tox.ini file as my command gets the &quot;&gt;foo.log&quot; as a CLI<br>
&gt; argument.<br>
&gt;<br>
&gt; Is there any non-obvious rationale for this?  If not, would you consider<br>
&gt; changes in this behavior?<br>
&gt;<br>
&gt; Thanks!<br>
&gt;<br>
&gt; André<br>
&gt;<br>
&gt;<br>
&gt; On Mon, Jun 13, 2016 at 12:54 PM, Florian Bruhin &lt;<a href="mailto:me@the-compiler.org">me@the-compiler.org</a>&gt;<br>
&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hey André,<br>
&gt;&gt;<br>
&gt;&gt; * André Caron &lt;<a href="mailto:andre.l.caron@gmail.com">andre.l.caron@gmail.com</a>&gt; [2016-06-13 12:07:37 -0400]:<br>
&gt;&gt; &gt; I looked through Tox&#39; docs and CLI help, but I can&#39;t find a &quot;silent&quot;<br>
&gt;&gt; &gt; mode<br>
&gt;&gt; &gt; or a way to force (only) Tox to write to stderr.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Do you have anything to recommend?  If not, any chance you would<br>
&gt;&gt; &gt; consider a<br>
&gt;&gt; &gt; patch to introduce a silent mode or a config change to send Tox&#39; logs to<br>
&gt;&gt; &gt; stederr?<br>
&gt;&gt;<br>
&gt;&gt; There&#39;s an issue for a -q flag, but nobody worked on it so far:<br>
&gt;&gt; <a href="https://bitbucket.org/hpk42/tox/issues/256/" rel="noreferrer" target="_blank">https://bitbucket.org/hpk42/tox/issues/256/</a><br>
&gt;&gt;<br>
&gt;&gt; I still want to work on that, but never got to it with all the other<br>
&gt;&gt; FOSS stuff I do :) So if you want to work on a patch, please do!<br>
&gt;&gt;<br>
&gt;&gt; Florian<br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; <a href="http://www.the-compiler.org" rel="noreferrer" target="_blank">http://www.the-compiler.org</a> | <a href="mailto:me@the-compiler.org">me@the-compiler.org</a> (Mail/XMPP)<br>
&gt;&gt;    GPG: 916E B0C8 FD55 A072 | <a href="http://the-compiler.org/pubkey.asc" rel="noreferrer" target="_blank">http://the-compiler.org/pubkey.asc</a><br>
&gt;&gt;          I love long mails! | <a href="http://email.is-not-s.ms/" rel="noreferrer" target="_blank">http://email.is-not-s.ms/</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; testing-in-python mailing list<br>
&gt; <a href="mailto:testing-in-python@lists.idyll.org">testing-in-python@lists.idyll.org</a><br>
&gt; <a href="http://lists.idyll.org/listinfo/testing-in-python" rel="noreferrer" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
&gt;<br>
</blockquote></div><br></div>