Summary. Why does the FastScripts application do the following, is it purposeful, and can I or FastScripts developers somehow fix/change the behavior to not do this? (I otherwise find FastScripts to be a superb application. I'm running MacOS 10.9.5.)
Details.
FastScripts 2.6.8 appears to copy the content of the current script its running to stdin
for any subprocess that runs in said script, as demonstrated by the command-line session below. Not only is this just plain weird, it can cause significant confusion when developing software triggered by FastScripts directives.
I've not tested similar behavior with non-Python scripts, but multiple independent Python programs I've written all behave the same way. I'll be emailing a link to this question to the FastScripts developers/technical support.
The following demonstrates the scripts running properly:
$ cat test_subprocess_stdin.py
#!/usr/bin/env python
import subprocess
cmd1 = '/tmp/reprint_stdin.py >/tmp/cmd1out.txt'
cmd2 = '/tmp/reprint_stdin.py </dev/null >/tmp/cmd2out.txt'
subprocess.Popen(cmd1, shell=True)
subprocess.Popen(cmd2, shell=True)
$ cat /tmp/reprint_stdin.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
# from http://stackoverflow.com/a/17735803/605356
stdin_content_present = not sys.stdin.isatty()
if stdin_content_present:
for line in sys.stdin:
sys.stdout.write('stdin: ' + line)
$ ./test_subprocess_stdin.py
$ cat /tmp/cmd1out.txt
$ cat /tmp/cmd2out.txt
$
However, strange stuff happens when running the above script(s) from FastScripts:
$ # <now running test_subprocess_stdin.py from FastScripts keyboard shortcut>
$
$ cat /tmp/cmd1out.txt
stdin: #!/usr/bin/env python
stdin: import subprocess
stdin: cmd1 = '/tmp/reprint_stdin.py >/tmp/cmd1out.txt'
stdin: cmd2 = '/tmp/reprint_stdin.py </dev/null >/tmp/cmd2out.txt'
stdin: subprocess.Popen(cmd1, shell=True)
stdin: subprocess.Popen(cmd2, shell=True)
$ cat /tmp/cmd2out.txt
$
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.9.5
BuildVersion: 13F1077
$
Note that calling os.system()
in place of subprocess.Popen()
causes same, anomalous behavior.
For some reason, FastScripts and only FastScripts seems to direct the content of the script it's running (in the above case, test_subprocess_stdin.py
) to the stdin of any (sub) script that gets called within the toplevel script/program. (The </dev/null
directs the called subscript to ignore stdin.) This is strange, and because of this, it took a lot of my development+debugging time to discover why my FastScript-called programs were breaking.