On 19Jan2022 19:16, James Smith <bjlockie...@gmail.com> wrote: >I'm trying to run a shell command but the stdout is empty: > >import subprocess > >torrentno=8 >cmd="/usr/bin/transmission-remote --torrent %s --info", str(torrentno) >res=subprocess.run(cmd, shell=True, check=True, universal_newlines=True, >capture_output=True) >print(res) > >CompletedProcess(args=('/usr/bin/transmission-remote --torrent %s --info', >'1'), returncode=0, stdout='', stderr='')
If you're using shell=True (please don't) you want cmd to be a string. You have defined it as a 2-tuple. You can even see that in the CompletedProcess object you printed. I think you want to % substitue torrentno into the format string. But I recommend you use shell=False and make: cmd = ["/usr/bin/transmission-remote", "--torrent", str(torrentno), "--info"] because assembling commands with % formatting is a recipe for injection attacks. Look up "Little Bobby Tables", which is an SQL example of what you're doing with the shell. Cheers, Cameron Simpson <c...@cskk.id.au> -- https://mail.python.org/mailman/listinfo/python-list