{"id":10951,"date":"2016-02-16T16:15:57","date_gmt":"2016-02-16T14:15:57","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=10951"},"modified":"2018-01-09T09:45:43","modified_gmt":"2018-01-09T07:45:43","slug":"python-subprocess-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/","title":{"rendered":"Python Subprocess Example"},"content":{"rendered":"<p>In this article, using Python 3.4, we&#8217;ll learn about Python&#8217;s <code>subprocess<\/code> module, which provides a high-level interface to interact with external commands.<\/p>\n<p>This module is intended to be a replacement to the old <code>os.system<\/code> and such modules. It provides all of the functionality of the other modules and functions it replaces. The API is consistent for all uses, and operations such as closing files and pipes are built in instead of being handled by the application code separately.<\/p>\n<p>One thing to notice is that the API is roughly the same, but the underlying implementation is slightly different between Unix and Windows. The examples provided here were tested on a Unix based system. Behavior on a non-Unix OS will vary.<\/p>\n<p>The <code>subprocess<\/code> module defines a class called <code>Popen<\/code> and some wrapper functions which take almost the same arguments as its constructor does. But for more advanced use cases, the <code>Popen<\/code> interface can be used directly.<\/p>\n<p>We&#8217;ll first take a look to all the wrapper functions and see what they do and how to call them. Then we&#8217;ll see how to use <code>Popen<\/code> directly to ease our thirst for knowledge.<br \/>\n[ulp id=&#8217;R7QVpFMZmjosABLC&#8217;]<\/p>\n<h2>1. Convenience Functions<\/h2>\n<h3>1.1. subprocess.call<\/h3>\n<p>The first function we&#8217;ll overview is <code>subprocess.call<\/code>. The most commonly used arguments it takes are <code>(args, *, stdin=None, stdout=None, stderr=None, shell=False, timeout=None)<\/code>. Although these are the most commonly used arguments, this function takes roughly as many arguments as <code>Popen<\/code> does, and it passes almost them all directly through to that interface. The only exception is the <code>timeout<\/code> which is passed to <code>Popen.wait()<\/code>, if the timeout expires, the child process will be killed and then waited for again. The TimeoutExpired exception will be re-raised after the child process has terminated.<\/p>\n<p>This function runs the command described by <code>args<\/code>, waits for the command to complete and returns the exit code attribute. Let&#8217;s see a trivial example:<\/p>\n<pre class=\"brush:bash\">\r\n$ python3\r\n&gt;&gt;&gt; import subprocess\r\n&gt;&gt;&gt; subprocess.call([\"ls\", \"-l\"])\r\n0\r\n<\/pre>\n<p>As you see, it&#8217;s returning 0, as it&#8217;s the return code of the <code>ls -l<\/code> command. You will probably see the output of the command in the console as it&#8217;s sent to standard output, but it won&#8217;t be available within your code using this command this way.<\/p>\n<p>Another thing to notice is that the command to run is being passed as an array, as the <code>Popen<\/code> interface will then concatenate and process the elements saving us the trouble of escaping quote marks and other special characters. You can avoid this notation by setting the <code>shell<\/code> flag to a <code>True<\/code> value, which will spawn an intermediate shell process and tell it to run the command, like this:<\/p>\n<pre class=\"brush:bash\">\r\n$ python3\r\n&gt;&gt;&gt; import subprocess\r\n&gt;&gt;&gt; subprocess.call(\"ls -l\", shell=True)\r\n0\r\n<\/pre>\n<p>Although the <code>shell=True<\/code> option might be useful to better exploit the most powerful tools the shell provides us, it can be a security risk, and you should keep this in mind. To use this tool in a safer way you can use <code>shlex.quote()<\/code> to properly escape whitespace and shell metacharacters in strings that are going to be used to construct shell commands. Let&#8217;s see and example of a security issue this can cause:<\/p>\n<p><span style=\"text-decoration: underline\"><em>security-issues.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nimport subprocess\r\nimport shlex\r\n\r\n\r\ndef unsafe(directory):\r\n    command = \"du -sh {}\".format(directory)\r\n    subprocess.call(command, shell=True)\r\n\r\n\r\ndef safe(directory):\r\n    sanitized_directory = shlex.quote(directory)\r\n    command = \"du -sh {}\".format(sanitized_directory)\r\n    subprocess.call(command, shell=True)\r\n\r\nif __name__ == \"__main__\":\r\n    directory = \"\/dev\/null; ls -l \/tmp\"\r\n    unsafe(directory)\r\n    safe(directory)\r\n\r\n<\/pre>\n<p>Here we have two functions. The first one, <code>unsafe<\/code>, will run a <code>du -sh<\/code> over a directory provided, without validating or cleaning it. The second one, <code>safe<\/code>, will apply the same command to a sanitized version of the provided directory. By providing a directory like <code>\"\/dev\/null; ls -l \/tmp\"<\/code>, we are trying to exploit the vulnerability to see what the contents of <code>\/tmp<\/code> are, of course it can get a lot uglier if a <code>rm<\/code> would intervene here.<\/p>\n<p>The <code>unsafe<\/code> function will output to stdout a line like <code>0       \/dev\/null<\/code> as the output of the <code>du -sh<\/code>, and then the contents of <code>\/tmp<\/code>. The <code>safe<\/code> method will fail, as no directory called <code>\"\/dev\/null; ls -l \/tmp\"<\/code> exists in the system.<\/p>\n<p>Now, as we said before, this function returns the exit code of the executed command, which give us the responsibility of interpreting it as a successful or an error code. Here comes the <code>check_call<\/code> function.<\/p>\n<h3>1.2. subprocess.check_call<\/h3>\n<p>This wrapper function takes the same arguments as <code>subprocess.call<\/code>, and behaves almost the same. The only difference is that it interprets the exit code for us.<\/p>\n<p>It runs the described command, waits for it to complete and, if the return code is zero, it returns, otherwise it will raise <code>CalledProcessError<\/code>. Let&#8217;s see:<\/p>\n<pre class=\"brush:bash\">\r\n$ python3\r\n&gt;&gt;&gt; import subprocess\r\n&gt;&gt;&gt; subprocess.check_call(\"exit 1\", shell=True)\r\nTraceback (most recent call last):\r\n  File \"&lt;stdin&gt;\", line 1, in &lt;module&gt;\r\n  File \"\/usr\/lib\/python3.4\/subprocess.py\", line 561, in check_call\r\n    raise CalledProcessError(retcode, cmd)\r\nsubprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1\r\n\r\n<\/pre>\n<p>The command <code>exit<\/code> will ask the shell to finish with the given exit code. As it is not zero, <code>CalledProcessError<\/code> is raised.<\/p>\n<p>One way of gaining access to the output of the executed command would be to use <code>PIPE<\/code> in the arguments <code>stdout<\/code> or <code>stderr<\/code>, but the child process will block if it generates enough output to a pipe to fill up the OS pipe buffer as the pipes are not being read from. So, having said that this method is not safe, let&#8217;s skip to the safe and easy way.<\/p>\n<h3>1.3. subprocess.check_output<\/h3>\n<p>This function receives almost the same arguments as the previous ones, but it adds <code>input<\/code> and <code>universal_newlines<\/code>. The <code>input<\/code> argument is passed to <code>Popen.communicate()<\/code> and thus to the command stdin. When it is uses, it should be a byte sequence, or a string if <code>universal_newlines=True<\/code>.<\/p>\n<p>Another change is in its behaviour, as it returns the output of the command. It will check the exit code of the command for you raising <code>CalledProcessError<\/code> if it&#8217;s not 0. Let&#8217;s see an example:<\/p>\n<pre class=\"brush:bash\">\r\n$ python3\r\n&gt;&gt;&gt; import subprocess\r\n&gt;&gt;&gt; subprocess.check_output([\"echo\", \"Hello world!\"])\r\nb'Hello world!\\n'\r\n&gt;&gt;&gt; subprocess.check_output([\"echo\", \"Hello World!\"], universal_newlines=True)\r\n'Hello World!\\n'\r\n&gt;&gt;&gt; subprocess.check_output([\"sed\", \"-e\", \"s\/foo\/bar\/\"], input=b\"when in the course of fooman events\\n\")\r\nb'when in the course of barman events\\n'\r\n&gt;&gt;&gt; subprocess.check_output([\"sed\", \"-e\", \"s\/foo\/bar\/\"], input=\"when in the course of fooman events\\n\", universal_newlines=True)\r\n'when in the course of barman events\\n'\r\n<\/pre>\n<p>Here you can see the variations of the two new arguments. The <code>input<\/code> argument is being passed to the <code>sed<\/code> command in the third and fourth statements, and the <code>universal_newlines<\/code> decodes the byte sequences into strings or not, depending on its value.<\/p>\n<p>Also, you can capture the standard error output by setting <code>stderr=subprocess.STDOUT<\/code>, but keep in mind that this will merge stdout and stderr, so you really need to know how to parse all that information into something you can use.<\/p>\n<h2>2. Popen<\/h2>\n<p>Now, let&#8217;s see how can we use <code>Popen<\/code> directly. I think with the explanation made before, you get an idea. Let&#8217;s see a couple of trivial use cases. We&#8217;ll start by rewriting the already written examples using <code>Popen<\/code> directly.<\/p>\n<pre class=\"brush:bash\">\r\n$ python3\r\n&gt;&gt;&gt; from subprocess import Popen\r\n&gt;&gt;&gt; proc = Popen([\"ls\", \"-l\"])\r\n&gt;&gt;&gt; proc.wait()\r\n0\r\n<\/pre>\n<p>Here, as your see, <code>Popen<\/code> is being instantiated passing only the command to run as an array of strings (just as we did before). <code>Popen<\/code>&#8216;s constructor also accepts the argument <code>shell<\/code>, but it&#8217;s still unsafe. This constructor starts the command execution the moment it is instantiated, but calling <code>Popen.wait()<\/code> will wait for the process to finish and return the exit code.<\/p>\n<p>Now, let&#8217;s see an example of <code>shell=True<\/code> just to see that it&#8217;s just the same:<\/p>\n<pre class=\"brush:bash\">\r\n$ python3\r\n&gt;&gt;&gt; from subprocess import Popen\r\n&gt;&gt;&gt; proc = Popen(\"ls -l\", shell=True)\r\n&gt;&gt;&gt; proc.wait()\r\n0\r\n<\/pre>\n<p>See? It behaves the same as the wrapper functions we saw before. It doesn&#8217;t seem so complicated now, does it? Let&#8217;s rewrite the <code>security-issues.py<\/code> example with it:<\/p>\n<p><span style=\"text-decoration: underline\"><em>security-issues-popen.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nfrom subprocess import Popen\r\nimport shlex\r\n\r\n\r\ndef unsafe(directory):\r\n    command = \"du -sh {}\".format(directory)\r\n    proc = Popen(command, shell=True)\r\n    proc.wait()\r\n\r\n\r\ndef safe(directory):\r\n    sanitized_directory = shlex.quote(directory)\r\n    command = \"du -sh {}\".format(sanitized_directory)\r\n    proc = Popen(command, shell=True)\r\n    proc.wait()\r\n\r\nif __name__ == \"__main__\":\r\n    directory = \"\/dev\/null; ls -l \/tmp\"\r\n    unsafe(directory)\r\n    safe(directory)\r\n\r\n<\/pre>\n<p>Now, if we execute this example, we&#8217;ll see it behaves the same as the one written with the <code>subprocess.call<\/code>.<\/p>\n<p>Now, <code>Popen<\/code>&#8216;s constructor will not raise any errors if the command exit code is not zero, its <code>wait<\/code> function will return the exit code and, again, it&#8217;s your responsibility to check it and perform any fallback.<\/p>\n<p>So, what if we want to gain access to the output? Well, <code>Popen<\/code> will receive the <code>stdout<\/code> and <code>stderr<\/code> arguments, which now are safe to use, as we are going to read from them. Let&#8217;s write a little example which let&#8217;s us see the size of a file\/directory.<\/p>\n<p><span style=\"text-decoration: underline\"><em>size.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nfrom subprocess import Popen, PIPE\r\n\r\n\r\ndef command(directory):\r\n    return [\"du\", \"-sh\", directory]\r\n\r\n\r\ndef check_size(directory):\r\n    proc = Popen(command(directory), stdout=PIPE, stderr=PIPE, universal_newlines=True)\r\n    result = \"\"\r\n    exit_code = proc.wait()\r\n    if exit_code != 0:\r\n        for line in proc.stderr:\r\n            result = result + line\r\n    else:\r\n        for line in proc.stdout:\r\n            result = result + line\r\n    return result\r\n\r\n\r\ndef main():\r\n    arg = input(\"directory to check: \")\r\n    result = check_size(directory=arg)\r\n    print(result)\r\n\r\nif __name__ == \"__main__\":\r\n    main()\r\n\r\n<\/pre>\n<p>Here we are instantiating a <code>Popen<\/code> and setting <code>stdout<\/code> and <code>stderr<\/code> to <code>subprocess.PIPE<\/code> to be able to read the output of our command, we are also setting <code>universal_newline<\/code> to <code>True<\/code> so we can work with strings. Then we are calling <code>Popen.wait()<\/code> and saving the exit code (notice that you can pass a timeout to the <code>wait<\/code> function) and, then printing the standard output of our command if it ran successfully, or the standard error output if else.<\/p>\n<p>Now, the last case scenario we are missing is sending stuff to the standard input of our command. Let&#8217;s write a script that interacts with our <code>size.py<\/code> sending a <em>hardcoded<\/em> directory to its stdin:<\/p>\n<p><span style=\"text-decoration: underline\"><em>size-of-tmp.py<\/em><\/span><\/p>\n<pre class=\"brush:python\">\r\nfrom subprocess import Popen, PIPE\r\n\r\n\r\ndef size_of_tmp():\r\n    proc = Popen([\"python3\", \"size.py\"], stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True)\r\n    (stdout, stderr) = proc.communicate(\"\/tmp\")\r\n    exit_code = proc.wait()\r\n    if exit_code != 0:\r\n        return stderr\r\n    else:\r\n        return stdout\r\n\r\nif __name__ == \"__main__\":\r\n    print(size_of_tmp())\r\n\r\n<\/pre>\n<p>Now, this last script will execute the first one, and as it asks for a directory to check, the new script will send <code>\"\/tmp\"<\/code> to its standard input.<\/p>\n<h2>3. Download the Code Project<\/h2>\n<p>This was a basic example on Python subprocesses.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/> You can download the full source code of this example here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/02\/subprocess-example.zip\"><strong>python-subprocess<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this article, using Python 3.4, we&#8217;ll learn about Python&#8217;s subprocess module, which provides a high-level interface to interact with external commands. This module is intended to be a replacement to the old os.system and such modules. It provides all of the functionality of the other modules and functions it replaces. The API is consistent &hellip;<\/p>\n","protected":false},"author":109,"featured_media":1651,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[335],"class_list":["post-10951","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-subprocess"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Subprocess Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In this article, using Python 3.4, we&#039;ll learn about Python&#039;s subprocess module, which provides a high-level interface to interact with external commands.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Subprocess Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In this article, using Python 3.4, we&#039;ll learn about Python&#039;s subprocess module, which provides a high-level interface to interact with external commands.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/sgvinci\" \/>\n<meta property=\"article:published_time\" content=\"2016-02-16T14:15:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-09T07:45:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sebastian Vinci\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sebastianvinci_\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sebastian Vinci\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/\"},\"author\":{\"name\":\"Sebastian Vinci\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/06a43c63e373dff2e159bbc029b405aa\"},\"headline\":\"Python Subprocess Example\",\"datePublished\":\"2016-02-16T14:15:57+00:00\",\"dateModified\":\"2018-01-09T07:45:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/\"},\"wordCount\":1325,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"keywords\":[\"subprocess\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/\",\"name\":\"Python Subprocess Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"datePublished\":\"2016-02-16T14:15:57+00:00\",\"dateModified\":\"2018-01-09T07:45:43+00:00\",\"description\":\"In this article, using Python 3.4, we'll learn about Python's subprocess module, which provides a high-level interface to interact with external commands.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Subprocess Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/06a43c63e373dff2e159bbc029b405aa\",\"name\":\"Sebastian Vinci\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g\",\"caption\":\"Sebastian Vinci\"},\"description\":\"Sebastian is a full stack programmer, who has strong experience in Java and Scala enterprise web applications. He is currently studying Computers Science in UBA (University of Buenos Aires) and working a full time job at a .com company as a Semi-Senior developer, involving architectural design, implementation and monitoring. He also worked in automating processes (such as data base backups, building, deploying and monitoring applications).\",\"sameAs\":[\"http:\/\/www.webcodegeeks.com\/\",\"https:\/\/www.facebook.com\/sgvinci\",\"https:\/\/x.com\/sebastianvinci_\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/sebastian-vinci\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Subprocess Example - Web Code Geeks - 2026","description":"In this article, using Python 3.4, we'll learn about Python's subprocess module, which provides a high-level interface to interact with external commands.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/","og_locale":"en_US","og_type":"article","og_title":"Python Subprocess Example - Web Code Geeks - 2026","og_description":"In this article, using Python 3.4, we'll learn about Python's subprocess module, which provides a high-level interface to interact with external commands.","og_url":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/sgvinci","article_published_time":"2016-02-16T14:15:57+00:00","article_modified_time":"2018-01-09T07:45:43+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","type":"image\/jpeg"}],"author":"Sebastian Vinci","twitter_card":"summary_large_image","twitter_creator":"@sebastianvinci_","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Sebastian Vinci","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/"},"author":{"name":"Sebastian Vinci","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/06a43c63e373dff2e159bbc029b405aa"},"headline":"Python Subprocess Example","datePublished":"2016-02-16T14:15:57+00:00","dateModified":"2018-01-09T07:45:43+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/"},"wordCount":1325,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","keywords":["subprocess"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/","url":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/","name":"Python Subprocess Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","datePublished":"2016-02-16T14:15:57+00:00","dateModified":"2018-01-09T07:45:43+00:00","description":"In this article, using Python 3.4, we'll learn about Python's subprocess module, which provides a high-level interface to interact with external commands.","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/python\/python-subprocess-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/www.webcodegeeks.com\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Subprocess Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/06a43c63e373dff2e159bbc029b405aa","name":"Sebastian Vinci","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/12d0233b49dd2a282330a987b16e81c3fbd4a8a8f5d5338348a6edd47cfff99e?s=96&d=mm&r=g","caption":"Sebastian Vinci"},"description":"Sebastian is a full stack programmer, who has strong experience in Java and Scala enterprise web applications. He is currently studying Computers Science in UBA (University of Buenos Aires) and working a full time job at a .com company as a Semi-Senior developer, involving architectural design, implementation and monitoring. He also worked in automating processes (such as data base backups, building, deploying and monitoring applications).","sameAs":["http:\/\/www.webcodegeeks.com\/","https:\/\/www.facebook.com\/sgvinci","https:\/\/x.com\/sebastianvinci_"],"url":"https:\/\/www.webcodegeeks.com\/author\/sebastian-vinci\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/10951","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/109"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=10951"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/10951\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/1651"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=10951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=10951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=10951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}