0

I am trying to write a script that extracts wifi passwords. The problem is, I don't want it to show output before it's fully done.

from subprocess import check_output
raw = check_output('security find-generic-password -ga test > /dev/null 2>&1',\
shell=True)

If I suppress output like this, then even variables won't get any output for further uses. So how to suppress output, but save it in a variable.

user16965639
  • 176
  • 11
  • 1
    Don't redirect the output to `/dev/null`. The default for `check_output()` is to save the output. – Barmar Oct 22 '21 at 19:44
  • Then it shows output in the terminal as well, which I am trying to avoid. – user16965639 Oct 22 '21 at 19:50
  • No it won't. `check_output()` redirects stdout to a pipe and captures the pipe's contents. – Barmar Oct 22 '21 at 19:52
  • 1
    If it's generating errors and you want to capture that, use `stderr=subprocess.STDOUT` to merge them. – Barmar Oct 22 '21 at 19:54
  • Use `raw = run('security ... -ga test', capture_output=True)` to automatically capture both standard output and standard error. The contents of each are then accessible from `raw.stdout` and `raw.stderr`, respectively. – chepner Oct 22 '21 at 20:36
  • what system do you use? unfortunately subprocess provide command execution and return result to output. `/dev/null` - not bad. I found similar topic with similar answers) [quiet version of subprocess.call](https://stackoverflow.com/a/8529412/3764369) [discard subprocess output](https://stackoverflow.com/a/12926181/3764369) – dzNET Oct 23 '21 at 10:38

1 Answers1

0
ping=$(ls >> output.txt)
rm -rf output.txt

Assume the above scenario. I am piping the sttdout to a file then removing the file. Result is the output is not seen.

Yada
  • 71
  • 4