Pipeline in Python w/o invoking the shell:<p><pre><code> username = input("Hello, what's your name? ")
p1 = Popen(["figlet", f"Welcome, {username}"], stdout=PIPE)
p2 = Popen(["lolcat", "-f"], stdin=p1.stdout, stdout=PIPE)
p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits.
banner = p2.communicate()[0]
print(banner)
</code></pre>
<a href="https://docs.python.org/3/library/subprocess.html#replacing-shell-pipeline" rel="nofollow">https://docs.python.org/3/library/subprocess.html#replacing-...</a><p>Don't use the shell unless you absolutely have to, and when you do have to, use shlex.quote for quoting arguments:<p><a href="https://docs.python.org/3/library/shlex.html#shlex.quote" rel="nofollow">https://docs.python.org/3/library/shlex.html#shlex.quote</a><p><pre><code> username = input("Hello, what's your name? ")
banner = check_output(f"figlet "Welcome, {quote(username)}" | lolcat -f", shell=True)
print(banner)
</code></pre>
For something this simple, you could also just use `subprocess.check_output` twice:<p><pre><code> username = input("Hello, what's your name? ")
banner = check_output(["figlet", f"Welcome, {username}"])
banner = check_output(["lolcat", "-f"], input=banner)
print(banner)</code></pre>