{"id":12911,"date":"2023-09-25T11:23:00","date_gmt":"2023-09-25T11:23:00","guid":{"rendered":"https:\/\/www.digitaldesignjournal.com\/?p=12911"},"modified":"2023-09-25T11:23:04","modified_gmt":"2023-09-25T11:23:04","slug":"python-subprocess-interactive","status":"publish","type":"post","link":"https:\/\/www.digitaldesignjournal.com\/python-subprocess-interactive\/","title":{"rendered":"Python Subprocess Interactive [In-Depth Tutorial]"},"content":{"rendered":"\n<p>You can use the <code>subprocess<\/code> module to run external commands and interact with them interactively. <\/p>\n\n\n\n<p>To achieve interactive communication with a subprocess, you can use the <code>subprocess.Popen<\/code> class and work with the standard input, output, and error streams of the subprocess. <\/p>\n\n\n\n<p>Here&#8217;s a basic example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> subprocess\n\n<span class=\"hljs-comment\"># Launch an interactive shell (e.g., Python shell)<\/span>\nproc = subprocess.Popen(\n    <span class=\"hljs-string\">\"python\"<\/span>,  <span class=\"hljs-comment\"># Command to run<\/span>\n    stdin=subprocess.PIPE,  <span class=\"hljs-comment\"># Redirect input to the subprocess<\/span>\n    stdout=subprocess.PIPE,  <span class=\"hljs-comment\"># Redirect output from the subprocess<\/span>\n    stderr=subprocess.PIPE,  <span class=\"hljs-comment\"># Redirect error output from the subprocess<\/span>\n    shell=<span class=\"hljs-literal\">True<\/span>  <span class=\"hljs-comment\"># Use the shell to execute the command<\/span>\n)\n\n<span class=\"hljs-comment\"># Communicate with the subprocess interactively<\/span>\n<span class=\"hljs-keyword\">while<\/span> <span class=\"hljs-literal\">True<\/span>:\n    user_input = input(<span class=\"hljs-string\">\"Enter a command (or 'exit' to quit): \"<\/span>)\n    \n    <span class=\"hljs-keyword\">if<\/span> user_input == <span class=\"hljs-string\">'exit'<\/span>:\n        <span class=\"hljs-keyword\">break<\/span>\n    \n    <span class=\"hljs-comment\"># Send the user's input to the subprocess<\/span>\n    proc.stdin.write(user_input.encode(<span class=\"hljs-string\">'utf-8'<\/span>) + <span class=\"hljs-string\">b'\\n'<\/span>)\n    proc.stdin.flush()\n    \n    <span class=\"hljs-comment\"># Read and print the subprocess's output and errors<\/span>\n    stdout_line = proc.stdout.readline().decode(<span class=\"hljs-string\">'utf-8'<\/span>)\n    stderr_line = proc.stderr.readline().decode(<span class=\"hljs-string\">'utf-8'<\/span>)\n    \n    <span class=\"hljs-keyword\">if<\/span> stdout_line:\n        print(<span class=\"hljs-string\">\"Subprocess Output:\"<\/span>, stdout_line, end=<span class=\"hljs-string\">''<\/span>)\n    \n    <span class=\"hljs-keyword\">if<\/span> stderr_line:\n        print(<span class=\"hljs-string\">\"Subprocess Error:\"<\/span>, stderr_line, end=<span class=\"hljs-string\">''<\/span>)\n\n<span class=\"hljs-comment\"># Close the subprocess and wait for it to finish<\/span>\nproc.stdin.close()\nproc.wait()\n\nprint(<span class=\"hljs-string\">\"Subprocess exited with return code:\"<\/span>, proc.returncode)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>We use <code>subprocess.Popen<\/code> to start an interactive shell (Python in this case) as a subprocess.<\/li>\n\n\n\n<li>We redirect the standard input, output, and error streams of the subprocess to Python&#8217;s standard input, output, and error streams using <code>stdin=subprocess.PIPE<\/code>, <code>stdout=subprocess.PIPE<\/code>, and <code>stderr=subprocess.PIPE<\/code>, respectively.<\/li>\n\n\n\n<li>We enter a loop where we read user input and send it to the subprocess using <code>proc.stdin.write<\/code>. We also read and print the subprocess&#8217;s output and error streams.<\/li>\n\n\n\n<li>The loop continues until the user enters &#8220;exit,&#8221; at which point we close the subprocess&#8217;s standard input, wait for it to finish, and print its return code.<\/li>\n<\/ol>\n\n\n\n<p>You can adapt this example to interact with other command-line tools or programs in an interactive manner.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Handling Interactive Shells With Python Subprocess<\/h2>\n\n\n\n<p>Handling interactive shells with Python&#8217;s <code>subprocess<\/code> module can be a bit more challenging than running simple commands because interactive shells require continuous interaction. Here&#8217;s a more advanced example that demonstrates how to handle an interactive shell:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> subprocess\r\n<span class=\"hljs-keyword\">import<\/span> os\r\n\r\n<span class=\"hljs-comment\"># Launch an interactive shell (e.g., \/bin\/bash)<\/span>\r\nshell = subprocess.Popen(\r\n    <span class=\"hljs-string\">\"\/bin\/bash\"<\/span>,  <span class=\"hljs-comment\"># Replace with the shell you want to use<\/span>\r\n    stdin=subprocess.PIPE,\r\n    stdout=subprocess.PIPE,\r\n    stderr=subprocess.PIPE,\r\n    text=<span class=\"hljs-literal\">True<\/span>,  <span class=\"hljs-comment\"># Use text mode to handle text input and output<\/span>\r\n    bufsize=<span class=\"hljs-number\">1<\/span>,  <span class=\"hljs-comment\"># Line-buffered, so we can read line by line<\/span>\r\n    shell=<span class=\"hljs-literal\">True<\/span>\r\n)\r\n\r\n<span class=\"hljs-comment\"># Function to send a command to the shell and read its output<\/span>\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">send_command<\/span><span class=\"hljs-params\">(command)<\/span>:<\/span>\r\n    shell.stdin.write(command + <span class=\"hljs-string\">'\\n'<\/span>)\r\n    shell.stdin.flush()\r\n    output = <span class=\"hljs-string\">''<\/span>\r\n    <span class=\"hljs-keyword\">while<\/span> <span class=\"hljs-literal\">True<\/span>:\r\n        line = shell.stdout.readline()\r\n        <span class=\"hljs-keyword\">if<\/span> line == <span class=\"hljs-string\">''<\/span> <span class=\"hljs-keyword\">and<\/span> shell.poll() <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-keyword\">not<\/span> <span class=\"hljs-literal\">None<\/span>:\r\n            <span class=\"hljs-keyword\">break<\/span>\r\n        output += line\r\n    <span class=\"hljs-keyword\">return<\/span> output\r\n\r\n<span class=\"hljs-comment\"># Interact with the shell<\/span>\r\n<span class=\"hljs-keyword\">while<\/span> <span class=\"hljs-literal\">True<\/span>:\r\n    user_input = input(<span class=\"hljs-string\">\"$ \"<\/span>)  <span class=\"hljs-comment\"># Prompt for user input<\/span>\r\n    <span class=\"hljs-keyword\">if<\/span> user_input.lower() == <span class=\"hljs-string\">'exit'<\/span>:\r\n        <span class=\"hljs-keyword\">break<\/span>\r\n\r\n    result = send_command(user_input)\r\n    print(result, end=<span class=\"hljs-string\">''<\/span>)\r\n\r\n<span class=\"hljs-comment\"># Close the shell<\/span>\r\nshell.stdin.close()\r\nshell.wait()\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>We use <code>subprocess.Popen<\/code> to launch an interactive shell (in this case, <code>\/bin\/bash<\/code>). Replace it with the shell or command you want to interact with.<\/li>\n\n\n\n<li>We set <code>text=True<\/code> to work with text-based input and output and <code>bufsize=1<\/code> to make the output line-buffered so we can read it line by line.<\/li>\n\n\n\n<li>We define a <code>send_command<\/code> function that sends a command to the shell and reads its output until it&#8217;s done executing. This function helps us interact with the shell.<\/li>\n\n\n\n<li>In the main loop, we read user input, send it to the shell, and print the output until the user enters &#8220;exit.&#8221;<\/li>\n\n\n\n<li>Finally, we close the shell&#8217;s stdin, wait for it to finish, and exit.<\/li>\n<\/ol>\n\n\n\n<p>Keep in mind that interacting with interactive shells can be tricky, and not all shells or programs behave the same way. You may need to adjust this code to work with the specific shell or program you want to interact with. Additionally, consider using more specialized libraries like <code>pexpect<\/code> or <code>pty<\/code> if you need more advanced features for interacting with a shell.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python Interactive Subprocess Communicate<\/h2>\n\n\n\n<p>In Python, you can use the <code>subprocess<\/code> module to communicate interactively with a subprocess. Here&#8217;s how you can create an interactive subprocess and communicate with it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> subprocess\r\n\r\n<span class=\"hljs-comment\"># Start an interactive subprocess (e.g., Python shell)<\/span>\r\nproc = subprocess.Popen(\r\n    <span class=\"hljs-string\">\"python\"<\/span>,  <span class=\"hljs-comment\"># Replace with the command you want to run<\/span>\r\n    stdin=subprocess.PIPE,  <span class=\"hljs-comment\"># Redirect input to the subprocess<\/span>\r\n    stdout=subprocess.PIPE,  <span class=\"hljs-comment\"># Redirect output from the subprocess<\/span>\r\n    stderr=subprocess.PIPE,  <span class=\"hljs-comment\"># Redirect error output from the subprocess<\/span>\r\n    text=<span class=\"hljs-literal\">True<\/span>,  <span class=\"hljs-comment\"># Use text mode for input\/output<\/span>\r\n    bufsize=<span class=\"hljs-number\">1<\/span>,  <span class=\"hljs-comment\"># Line-buffered for reading output line by line<\/span>\r\n    shell=<span class=\"hljs-literal\">True<\/span>  <span class=\"hljs-comment\"># Use the shell to execute the command<\/span>\r\n)\r\n\r\n<span class=\"hljs-comment\"># Define a function to send a command to the subprocess and get its output<\/span>\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">send_command<\/span><span class=\"hljs-params\">(command)<\/span>:<\/span>\r\n    proc.stdin.write(command + <span class=\"hljs-string\">'\\n'<\/span>)\r\n    proc.stdin.flush()\r\n    output = <span class=\"hljs-string\">''<\/span>\r\n    <span class=\"hljs-keyword\">while<\/span> <span class=\"hljs-literal\">True<\/span>:\r\n        line = proc.stdout.readline()\r\n        <span class=\"hljs-keyword\">if<\/span> <span class=\"hljs-keyword\">not<\/span> line:\r\n            <span class=\"hljs-keyword\">break<\/span>\r\n        output += line\r\n    <span class=\"hljs-keyword\">return<\/span> output\r\n\r\n<span class=\"hljs-comment\"># Interact with the subprocess<\/span>\r\n<span class=\"hljs-keyword\">while<\/span> <span class=\"hljs-literal\">True<\/span>:\r\n    user_input = input(<span class=\"hljs-string\">\"Enter a command (or 'exit' to quit): \"<\/span>)\r\n    <span class=\"hljs-keyword\">if<\/span> user_input == <span class=\"hljs-string\">'exit'<\/span>:\r\n        <span class=\"hljs-keyword\">break<\/span>\r\n\r\n    result = send_command(user_input)\r\n    print(result)\r\n\r\n<span class=\"hljs-comment\"># Close the subprocess and wait for it to finish<\/span>\r\nproc.stdin.close()\r\nproc.wait()\r\n\r\nprint(<span class=\"hljs-string\">\"Subprocess exited with return code:\"<\/span>, proc.returncode)\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this code:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>We start an interactive subprocess (in this example, the Python shell) using <code>subprocess.Popen<\/code>. You should replace <code>\"python\"<\/code> with the command you want to run.<\/li>\n\n\n\n<li>We use <code>stdin=subprocess.PIPE<\/code> to redirect input to the subprocess, and <code>stdout=subprocess.PIPE<\/code> and <code>stderr=subprocess.PIPE<\/code> to capture its output and error streams.<\/li>\n\n\n\n<li>We set <code>text=True<\/code> to work with text-based input and output and <code>bufsize=1<\/code> to make the output line-buffered so we can read it line by line.<\/li>\n\n\n\n<li>We define a <code>send_command<\/code> function that sends a command to the subprocess, flushes the input buffer, and reads the output until it&#8217;s done executing.<\/li>\n\n\n\n<li>In the main loop, we read user input, send it to the subprocess, and print the output until the user enters &#8220;exit.&#8221;<\/li>\n\n\n\n<li>Finally, we close the subprocess&#8217;s stdin, wait for it to finish, and print its return code.<\/li>\n<\/ol>\n\n\n\n<p>This code allows you to interact with a subprocess in an interactive manner and read its output as it&#8217;s generated. Modify the <code>send_command<\/code> function and subprocess command as needed for your specific use case.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How To Control An Interactive Ssh Session With Python&#8217;s Subprocess<\/h2>\n\n\n\n<p>You can control an interactive SSH session using Python&#8217;s <code>subprocess<\/code> module by launching the <code>ssh<\/code> command as a subprocess and communicating with it interactively. To achieve this, you can use the <code>paramiko<\/code> library to handle SSH connections and subprocess communication. Here&#8217;s a step-by-step guide:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Install the <code>paramiko<\/code> library if you haven&#8217;t already:<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">pip install paramiko\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ol class=\"wp-block-list\" start=\"2\">\n<li>Use the following Python code to establish an SSH connection and interact with it:<\/li>\n<\/ol>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> paramiko\r\n<span class=\"hljs-keyword\">import<\/span> subprocess\r\n<span class=\"hljs-keyword\">import<\/span> sys\r\n\r\n<span class=\"hljs-comment\"># SSH credentials and host information<\/span>\r\nssh_host = <span class=\"hljs-string\">'example.com'<\/span>  <span class=\"hljs-comment\"># Replace with the hostname or IP address of the SSH server<\/span>\r\nssh_port = <span class=\"hljs-number\">22<\/span>             <span class=\"hljs-comment\"># SSH port (default is 22)<\/span>\r\nssh_username = <span class=\"hljs-string\">'username'<\/span>  <span class=\"hljs-comment\"># SSH username<\/span>\r\nssh_password = <span class=\"hljs-string\">'password'<\/span>  <span class=\"hljs-comment\"># SSH password<\/span>\r\n\r\n<span class=\"hljs-comment\"># Create an SSH client instance<\/span>\r\nssh_client = paramiko.SSHClient()\r\nssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())\r\n\r\n<span class=\"hljs-keyword\">try<\/span>:\r\n    <span class=\"hljs-comment\"># Connect to the SSH server<\/span>\r\n    ssh_client.connect(ssh_host, port=ssh_port, username=ssh_username, password=ssh_password)\r\n\r\n    <span class=\"hljs-comment\"># Start an interactive shell session<\/span>\r\n    ssh_shell = ssh_client.invoke_shell()\r\n    \r\n    <span class=\"hljs-comment\"># Create subprocesses to handle SSH communication<\/span>\r\n    ssh_to_subprocess = ssh_shell.makefile(<span class=\"hljs-string\">\"rb\"<\/span>)\r\n    subprocess_to_ssh = ssh_shell.makefile(<span class=\"hljs-string\">\"wb\"<\/span>)\r\n\r\n    <span class=\"hljs-comment\"># Function to send commands to the SSH session<\/span>\r\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">send_ssh_command<\/span><span class=\"hljs-params\">(command)<\/span>:<\/span>\r\n        subprocess_to_ssh.write(command + <span class=\"hljs-string\">\"\\n\"<\/span>)\r\n        subprocess_to_ssh.flush()\r\n\r\n    <span class=\"hljs-keyword\">while<\/span> <span class=\"hljs-literal\">True<\/span>:\r\n        user_input = input(<span class=\"hljs-string\">\"$ \"<\/span>)\r\n        <span class=\"hljs-keyword\">if<\/span> user_input.lower() == <span class=\"hljs-string\">'exit'<\/span>:\r\n            <span class=\"hljs-keyword\">break<\/span>\r\n\r\n        send_ssh_command(user_input)\r\n\r\n        <span class=\"hljs-comment\"># Read and display the output from the SSH session<\/span>\r\n        <span class=\"hljs-keyword\">while<\/span> ssh_shell.recv_ready():\r\n            output = ssh_shell.recv(<span class=\"hljs-number\">1024<\/span>).decode(<span class=\"hljs-string\">'utf-8'<\/span>)\r\n            sys.stdout.write(output)\r\n            sys.stdout.flush()\r\n\r\n<span class=\"hljs-keyword\">finally<\/span>:\r\n    <span class=\"hljs-comment\"># Close the SSH client<\/span>\r\n    ssh_client.close()\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Replace the placeholders with your SSH server credentials (hostname, port, username, and password).<\/p>\n\n\n\n<p>In this code:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We create an SSH client instance using <code>paramiko<\/code> and connect to the SSH server.<\/li>\n\n\n\n<li>We start an interactive shell session on the server using <code>invoke_shell<\/code>.<\/li>\n\n\n\n<li>Two subprocesses (<code>ssh_to_subprocess<\/code> and <code>subprocess_to_ssh<\/code>) are created to handle communication between Python and the SSH session.<\/li>\n\n\n\n<li>The <code>send_ssh_command<\/code> function is used to send commands to the SSH session.<\/li>\n\n\n\n<li>In the main loop, we read user input, send it to the SSH session, and display the output until the user enters &#8220;exit.&#8221;<\/li>\n\n\n\n<li>Finally, we close the SSH client when done.<\/li>\n<\/ul>\n\n\n\n<p>This code allows you to control an interactive SSH session from Python and interact with the remote server as if you were using a terminal.<\/p>\n\n\n\n<p><strong>Read More;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/python-detach-subprocess-and-exit-with-examples\/\">Python Detach Subprocess And Exit<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/subprocess-communicate\/\">How to use the subprocess Popen.communicate() method<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/python-subprocess-output-to-file\/\">Python Subprocess Output To File<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/python-subprocess-output-to-variable\/\">Python Subprocess Output To Variable<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/multiple-commands-with-ssh-using-python-subprocess\/\">Multiple Commands With SSH Using Python Subprocess<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/python-subprocess-run-in-background-with-example\/\">Python Subprocess Run In Background<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/python-execute-shell-command-and-get-output\/\">Python Execute Shell Command And Get Output<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/face-recognition-based-attendance-system-using-python\/\">Face Recognition Based Attendance System Using Python<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/python-subprocess-pipe-with-example\/\">Python Subprocess Pipe With Example<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/subprocess-run\/\">Learn Subprocess.run() in Python<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/subprocess-popen-to-multiprocessing\/\">subprocess.Popen to multiprocessing&nbsp;<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitaldesignjournal.com\/python-subprocess-multiple-arguments\/\">Python Subprocess Multiple Arguments<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>You can use the subprocess module to run external commands and interact with them interactively. To achieve interactive communication with &#8230; <a title=\"Python Subprocess Interactive [In-Depth Tutorial]\" class=\"read-more\" href=\"https:\/\/www.digitaldesignjournal.com\/python-subprocess-interactive\/\" aria-label=\"More on Python Subprocess Interactive [In-Depth Tutorial]\">Read more<\/a><\/p>\n","protected":false},"author":14,"featured_media":12917,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92],"tags":[154],"ppma_author":[155],"class_list":["post-12911","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-subprocess-in-python","author-aniket-singh"],"authors":[{"term_id":155,"user_id":14,"is_guest":0,"slug":"aniket-singh","display_name":"Aniket Singh","avatar_url":{"url":"https:\/\/www.digitaldesignjournal.com\/wp-content\/uploads\/2023\/09\/Aniket_Singh.png","url2x":"https:\/\/www.digitaldesignjournal.com\/wp-content\/uploads\/2023\/09\/Aniket_Singh.png"},"0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/posts\/12911","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/comments?post=12911"}],"version-history":[{"count":6,"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/posts\/12911\/revisions"}],"predecessor-version":[{"id":12920,"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/posts\/12911\/revisions\/12920"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/media\/12917"}],"wp:attachment":[{"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/media?parent=12911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/categories?post=12911"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/tags?post=12911"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.digitaldesignjournal.com\/wp-json\/wp\/v2\/ppma_author?post=12911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}