{"id":5449,"date":"2024-11-20T06:33:57","date_gmt":"2024-11-20T06:33:57","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=5449"},"modified":"2026-02-02T09:21:01","modified_gmt":"2026-02-02T09:21:01","slug":"how-to-execute-system-command-in-python","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/","title":{"rendered":"How to Execute System Command in Python"},"content":{"rendered":"\n<p>Sometimes software developers need to run program or execute system command in Python. This is commonly required to perform background tasks and critical processes. For example, they may want to run shell script from Python program. There are several ways to do this in Python. In this article, we will learn how to run shell commands in Python.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#Why_Run_Shell_Commands_in_Python\" >Why Run Shell Commands in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#What_is_OS_module\" >What is OS module<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#What_is_Subprocess\" >What is Subprocess<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#How_to_Execute_Program_or_System_Command_in_Python\" >How to Execute Program or System Command in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#1_Using_subprocessPopen\" >1. Using subprocess.Popen()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#2_Using_subprocessrun\" >2. Using subprocess.run()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#3_Using_subprocesscall\" >3. Using subprocess.call()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#4_Using_subprocesscheck_output\" >4. Using subprocess.check_output()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#5_Using_ossystem\" >5. Using os.system()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#6_Using_ospopen\" >6. Using os.popen()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_Run_Shell_Commands_in_Python\"><\/span>Why Run Shell Commands in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>There are several reasons why developers need to run system commands and programs from within Python.<\/p>\n\n\n\n<p>Often software developers need to run critical commands or background processes along with their applications\/websites. They may be OS related commands or file manipulations. They need to do this without disturbing the execution thread of their main Python program. That is why it is super useful to be able to run shell commands in Python. For example, it is lot easier to run critical backups and system maintenance commands this way instead of using Python modules for this purpose.<\/p>\n\n\n\n<p>Another reason is that there are some things that are are easily done using system commands. For example, file manipulation is a lot easier using shell commands such as mv, cp, etc. instead of doing it using Python script.<\/p>\n\n\n\n<p>Sometimes, you may also need to run one Python script from within another Python script. In this case also, you can use this solution.<\/p>\n\n\n\n<p>Lastly, it saves a lot of coding, since you already have many system commands and programs at your disposal. You just need to call them from your Python script instead of coding them from scratch.<\/p>\n\n\n\n<p>Python provides two main modules, subprocess and os, for this purpose. Each of them provide multiple functions to run system commands and programs. Let us learn a little bit about these two modules.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_OS_module\"><\/span>What is OS module<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Python provides OS module that provides many useful functions &amp; constants to interact with underlying operating system. You can use the same commands to work with different operating systems. It allows you to create &amp; modify files &amp; directories. You can also use it to manage input, output, processes and environment variables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_Subprocess\"><\/span>What is Subprocess<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Subprocess is a helper module built to replace several functions of OS module. But over time, it has evolved into a robust and comprehensive library. It also allows you to create files, directories and processes, work with their input\/output\/errors. Its functions are a little more complicated than those provided by OS module. But its main advantage is that subprocess functions provide better control over system commands by returning a handle, as well as error codes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Execute_Program_or_System_Command_in_Python\"><\/span>How to Execute Program or System Command in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us look at the key functions provided by subprocess and os modules, that can be used to run system commands from Python.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_subprocessPopen\"><\/span>1. Using subprocess.Popen()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>subprocess.Popen() is a popular upgrade to os.popen() command (below) that is more comprehensive and versatile. It has a slightly complicated syntax but handles most use cases easily. You can pass the command as a string, or a list. Here is an example to pass command as a string.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import subprocess<br><br>subprocess.Popen('ls -all')<\/pre>\n\n\n\n<p>Here is an example where the command is passed as a list. In this case, you do not need to worry about escaping.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import subprocess<br>subprocess.popen(['ls','-l'])<\/pre>\n\n\n\n<p>In above cases, subprocess will spawn a separate process to run the command. If you want to run the process in shell itself, you can pass shell=True argument.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import subprocess<br>subprocess.popen(['ls','-l'], shell=True)<br><br>OR <br><br>import subprocess<br>subprocess.popen('ls -all', shell=True)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_subprocessrun\"><\/span>2. Using subprocess.run()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you run Python 3.5+, you can also use subprocess.run() function to execute system command in Python. Its syntax is similar to that of subprocess.Popen(). It requires you to pass the command as a list of strings, and not a string. It is more flexible than using subprocess.Popen() as it returns a process object on completion of command. It also supports shell=True argument like subprocess.Popen().<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import subprocess<br>subprocess.run([\"ls\", \"-a\"], shell=True)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_subprocesscall\"><\/span>3. Using subprocess.call()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>subprocess.call() is an old function available on python &lt;= 3.4. In fact, on older Python versions you will not find subprocess.run() and you will need to use this function instead. Its syntax is similar to that of system.run() function. You need to pass the command, along with its arguments, as a list of strings. It also allows you to run the command in a shell using shell=True option. Here is an example to run ls command using system.call().<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import subprocess<br>subprocess.call([\"ls\", \"-a\"], shell=True)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_subprocesscheck_output\"><\/span>4. Using subprocess.check_output()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Often software developers need to not only run system commands but also store their outputs for later use. You can store the output of your command using subprocess.check_output() function. Here is an example to illustrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import subprocess<br>out = subprocess.check_output('date')<br>print('Current date is:', out.decode(\"utf-8\"))<\/pre>\n\n\n\n<p>subprocess.check_output() returns the output as byte string. You need to call decode() function to convert it into UTF-8 string. Here is the output of above code.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">('Current date is:', u'Wed Nov 20 06:23:30 UTC 2024\\n')<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_ossystem\"><\/span>5. Using os.system()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>OS module offers system() command that is one of the oldest and reliable ways to run system commands in Python. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">os.system(command)<\/pre>\n\n\n\n<p>You can use it to pass arguments as well as run multiple commands, along with them input and output redirection. Here is are some examples to illustrate its use.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import os<br><br>os.system('pwd')<br>os.system(\"ls -all | grep 'test'\")<\/pre>\n\n\n\n<p>Please note, in the last command above, we enclose the substring to be searched within single quotes, whereas the actual command within double quotes, to avoid conflict. You will need to escape special characters while using them in os.system().<\/p>\n\n\n\n<p>Os.sytem() does not return any file handler that you can use to control the process. Once you call this function, it will start running the command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Using_ospopen\"><\/span>6. Using os.popen()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Os.popen() is another function that you can use to run programs and scripts from within Python. It is more flexible than using os.system() since it gives you a file object to handle its input, output and error. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">os.popen(command, mode, buf_size)<\/pre>\n\n\n\n<p>You can pass command, including arguments, as a string. Here are examples to demonstrate it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import os<br>os.popen('ls -l').read()<\/pre>\n\n\n\n<p>In the above case, the command string is directly sent to shell. So you may need to escape the special characters in it. <\/p>\n\n\n\n<p>Here is an example to save the file object returns by os.popen() and use it to control the process.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import os<br><br>f = os.popen('ls -a').read()<br>f.close()<\/pre>\n\n\n\n<p>You can also use these functions to perform other tasks such as <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-copy-files-in-python\/\">copy files in Python<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several different ways to easily run programs and system command in Python. You can use any of these methods as per your requirement. Using subprocess module offers more control and flexibility than using OS module.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-if-file-exists-in-python\/\">How to Check If File Exists in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-merge-two-dictionaries-in-python\/\">How to Merge Two Dictionaries in Python<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-split-list-into-even-chunks-in-python\/\">How to Split Python List Into Even Chunks<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Software developers need to execute shell commands from Python. Here is how to execute program or system commands in Python.<\/p>\n","protected":false},"author":1,"featured_media":5476,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[301],"tags":[333],"class_list":["post-5449","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 v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Execute System Command in Python - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Software developers need to execute shell commands from Python. Here is how to execute program or system command in Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Execute System Command in Python - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Software developers need to execute shell commands from Python. Here is how to execute program or system command in Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-20T06:33:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-02T09:21:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/run-system-command-in-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"308\" \/>\n\t<meta property=\"og:image:height\" content=\"204\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Execute System Command in Python\",\"datePublished\":\"2024-11-20T06:33:57+00:00\",\"dateModified\":\"2026-02-02T09:21:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/\"},\"wordCount\":1108,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/run-system-command-in-python.jpg?fit=308%2C204&ssl=1\",\"keywords\":[\"subprocess\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/\",\"name\":\"How to Execute System Command in Python - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/run-system-command-in-python.jpg?fit=308%2C204&ssl=1\",\"datePublished\":\"2024-11-20T06:33:57+00:00\",\"dateModified\":\"2026-02-02T09:21:01+00:00\",\"author\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Software developers need to execute shell commands from Python. Here is how to execute program or system command in Python.\",\"breadcrumb\":{\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/run-system-command-in-python.jpg?fit=308%2C204&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/run-system-command-in-python.jpg?fit=308%2C204&ssl=1\",\"width\":308,\"height\":204,\"caption\":\"run system command in python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/ubiq.co\/tech-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Execute System Command in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#website\",\"url\":\"https:\/\/ubiq.co\/tech-blog\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/\"],\"url\":\"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Execute System Command in Python - Ubiq BI","description":"Software developers need to execute shell commands from Python. Here is how to execute program or system command in Python.","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:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Execute System Command in Python - Ubiq BI","og_description":"Software developers need to execute shell commands from Python. Here is how to execute program or system command in Python.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2024-11-20T06:33:57+00:00","article_modified_time":"2026-02-02T09:21:01+00:00","og_image":[{"width":308,"height":204,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/run-system-command-in-python.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Execute System Command in Python","datePublished":"2024-11-20T06:33:57+00:00","dateModified":"2026-02-02T09:21:01+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/"},"wordCount":1108,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/run-system-command-in-python.jpg?fit=308%2C204&ssl=1","keywords":["subprocess"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/","name":"How to Execute System Command in Python - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/run-system-command-in-python.jpg?fit=308%2C204&ssl=1","datePublished":"2024-11-20T06:33:57+00:00","dateModified":"2026-02-02T09:21:01+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Software developers need to execute shell commands from Python. Here is how to execute program or system command in Python.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/run-system-command-in-python.jpg?fit=308%2C204&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/run-system-command-in-python.jpg?fit=308%2C204&ssl=1","width":308,"height":204,"caption":"run system command in python"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-execute-system-command-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Execute System Command in Python"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/run-system-command-in-python.jpg?fit=308%2C204&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1pT","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=5449"}],"version-history":[{"count":29,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5449\/revisions"}],"predecessor-version":[{"id":10499,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5449\/revisions\/10499"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/5476"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=5449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=5449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=5449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}