Python Tutorial: Calling External Commands Using the Subprocess Module

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 พ.ย. 2024

ความคิดเห็น • 382

  • @coreyms
    @coreyms  5 ปีที่แล้ว +232

    Hey everyone. I hope you found this video useful. As I mentioned in a previous post, I just finished renovating a house that I'm selling and am currently going through a cross-country move, so I haven't been able to post as much lately as I'd like. Once I get this house sold and get settled into my new place then I'll be releasing at a much faster pace. Thanks for your patience... especially those who are contributing through Patreon or are Channel Members! I appreciate all of you! Hope you're all having a great week!

    • @priteshugrankar6815
      @priteshugrankar6815 5 ปีที่แล้ว +3

      Hi Corey, happy house shifting. Thank you for such amazing content.
      Would you also be coming up with golang videos? If so, it will be truly awesome.

    • @realplod
      @realplod 5 ปีที่แล้ว +3

      Where are you moving?:)

    • @buacomgiadinh1
      @buacomgiadinh1 5 ปีที่แล้ว

      Is there any intention for golang programming

    • @coreyms
      @coreyms  5 ปีที่แล้ว +3

      realplod I’m moving from Colorado to North Carolina.

    • @undisclosedmusic4969
      @undisclosedmusic4969 5 ปีที่แล้ว +1

      Good luck with the move! Also: Docker tutorials? ❤️

  • @jonathanhenyolson
    @jonathanhenyolson 5 ปีที่แล้ว +108

    I know you have about a million things on your to-do list but a series or video on threading would be amazing. There's pretty sparse TH-cam content on it so far and one of your videos could easily fill that void! Thanks for all the great content!

    • @tanmoypaul1362
      @tanmoypaul1362 5 ปีที่แล้ว

      I second this. A video on threading would be awesome.

    • @user-be8ud2qd2d
      @user-be8ud2qd2d 5 ปีที่แล้ว

      @@tanmoypaul1362 Yeah I'd love this aswell

  • @ibrahimal-mahfooz8737
    @ibrahimal-mahfooz8737 5 ปีที่แล้ว +32

    Your content is as simple as sipping water for beginners. At the same time, I'm pretty sure it is so difficult to create and deliver such a clean and crystal clear content. Well done.

    • @coreyms
      @coreyms  5 ปีที่แล้ว +1

      Thanks!

  • @I_Follow_Jesus
    @I_Follow_Jesus 5 ปีที่แล้ว +12

    I've been taking Python courses online for certificates. Corey explains Python better that my online instructors.

  • @Hunt3rGatherer
    @Hunt3rGatherer 10 หลายเดือนก่อน +1

    Man I watched this 3 years ago with zero knowledge of computers other than a beginner python course and my brain short circuited. I finally understand everything in this video lol. Been using your videos for years now thanks bro 🤙

  • @jasonhales262
    @jasonhales262 2 ปีที่แล้ว

    This is by far the best explanation of the subprocess module on the WHOLE INTERNET.

  • @Yasharvl
    @Yasharvl 4 ปีที่แล้ว +2

    Corey, there's no doubt that these videos are a real must for anyone, who's learning Python.

  • @martym2908
    @martym2908 3 ปีที่แล้ว

    I googled a dozen didn't pages to get subprocess to work and haven't succeeded until i watched this. Thanks a ton !

  • @bhushanhiwase121
    @bhushanhiwase121 4 ปีที่แล้ว +8

    You are the best Corey, You have made my life so simple, and each one of your videos is so full of information and handy tricks. I really appreciate the work you put on to bring out these videos. Cannot be more Thankful... Huge Respect man...

  • @brijesh0808
    @brijesh0808 9 หลายเดือนก่อน

    This video is far far better than any documentation, blog or video content whether on youtube or udemy.

  • @Jack-sh4uv
    @Jack-sh4uv 3 ปีที่แล้ว +1

    I just want to say how helpful all your videos are, I really would get so stuck on the occasional small thing but your videos are consistently well thought out and progress at a good speed. Thanks for the help

  • @kobas8361
    @kobas8361 5 ปีที่แล้ว +109

    Love watching Corey's videos stoned. Being a programmer is so beautiful.

    • @youtuberecommended9183
      @youtuberecommended9183 4 ปีที่แล้ว +8

      Love your helicopter!

    • @crackindenpockets6211
      @crackindenpockets6211 4 ปีที่แล้ว +3

      i support marijuana use

    • @steez4778
      @steez4778 4 ปีที่แล้ว +8

      @@youtuberecommended9183 bruh

    • @HK-sw3vi
      @HK-sw3vi 4 ปีที่แล้ว +1

      how's watching his videos dead?

    • @peternau1346
      @peternau1346 4 ปีที่แล้ว +1

      Unfortunately, you won't remember any of it.

  • @sumukhas5418
    @sumukhas5418 ปีที่แล้ว +1

    This is the best explanation of a code I have ever seen!!

  • @suhaibalrabee9399
    @suhaibalrabee9399 5 หลายเดือนก่อน +2

    I couldn't find such explanation for this topic in my overpriced premium subscriptions (CBT, PS, Orielly).
    This should not be free, please keep up the great work, thanks!

    • @coreyms
      @coreyms  5 หลายเดือนก่อน

      Thanks so much!

  • @kariminic
    @kariminic 5 ปีที่แล้ว +2

    I found this video very useful. Had came across subprocess from the automate the boring stuff book but then didn't understand their purpose untill I watched this video. Have done really cool stuff with it, I had even to revisit the module from the book. In the end you've mentioned about Unicode, I haven't found a meaningful video on the topic and books full of jargons. I bet a video from you will be my saviour in understanding the topic. Thanks @Corey for the exceptional python tutorials.

  • @avahsieh4645
    @avahsieh4645 4 ปีที่แล้ว +2

    Your tutorial helps me more than the python official document does.
    Thank you.

  • @mayankpant5471
    @mayankpant5471 3 ปีที่แล้ว

    this man makes everything very ez. python semantics itself are very ez but his videos makes learning python like learning alphabets.

  • @grjesus9979
    @grjesus9979 3 ปีที่แล้ว +2

    This is what i can say linear learning look like, as it should always be, step by step and as clear as possible. Thank you a lot sir!

  • @ItzSenaCrazy
    @ItzSenaCrazy 5 ปีที่แล้ว +2

    This tutorial arrived on right time. I'm coding a program to manage all my VENVs.
    Thanks Corey!

  • @christianhaugen9462
    @christianhaugen9462 3 ปีที่แล้ว +1

    You are one of my favorite youtubers. I really appreciate how clear you communicate these concepts and teach them so well. I'll always be subscribed to you Corey!

  • @kaiwalyapethe2931
    @kaiwalyapethe2931 5 ปีที่แล้ว +6

    Encode-decode strings, waiting for it.. Great work Corey! Thanks for the videos.

    • @carlosrivadulla8903
      @carlosrivadulla8903 5 ปีที่แล้ว

      also how to encode an script but that still working when other user execute it to avoid copyright violation

  • @chiragpalan9780
    @chiragpalan9780 3 ปีที่แล้ว

    Each time I search something about python and I found Corey.. Great.

  • @BhajanSansar
    @BhajanSansar 4 ปีที่แล้ว

    Very helpful video. Just what i needed. Subscribed!

  • @happy0memo
    @happy0memo 3 ปีที่แล้ว +1

    Hi Corey, your video was fantastic! You were able to describe the content in a way that made sense. I have been trying to understand this for about 3 days now and your 19min clip nailed it to the point where i can simply grasp the concepts. In fact, i have been trying to solve a code problem and you helped me a lot. Great work and keep up the good content.

  • @RinksRides
    @RinksRides 3 ปีที่แล้ว

    Clear, concise, and great production quality! Subbed.

  • @roboroogo
    @roboroogo 5 ปีที่แล้ว +1

    Easily some of the best python content on you tube. Many thanks

  • @AndreyLLIaBepMa
    @AndreyLLIaBepMa 5 ปีที่แล้ว +3

    Great tutorial! Magnificent library! Thank you, Coray! You are doing a great work!

  • @bloodywolftr
    @bloodywolftr ปีที่แล้ว +1

    Thank you very much Corey.This is exactly what I was searching for and you explained it in a nutshell.

  • @kalpanarendarreddy5417
    @kalpanarendarreddy5417 ปีที่แล้ว

    My best teacher of python forever.......................love u corey ❤ 💕 always

  • @lingxu5598
    @lingxu5598 2 ปีที่แล้ว

    Another amazing video from my best CS teacher Corey...

  • @monotone31
    @monotone31 4 ปีที่แล้ว +5

    Users on Windows: use the following when Corey goes over 'cat' and 'grep'
    p1 = subprocess.run(['type', 'test.txt'], shell=True, capture_output=True, text=True)
    p2 = subprocess.run(['findstr', '/N', 'test'], shell=True, capture_output=True, text=True, input=p1.stdout)
    print(p2.stdout)

  • @maxrodriguez643
    @maxrodriguez643 3 ปีที่แล้ว +1

    Really useful! I am loving this subprocess module

  • @AnasAlsayedStudio
    @AnasAlsayedStudio 5 ปีที่แล้ว +29

    just wanna say that you're the best in delivering tutorial I've ever seen in youtube :D
    I hope if you make a tutorial about Vue js + Django
    will be really nice and original tutorial

    • @sharifahmed1925
      @sharifahmed1925 5 ปีที่แล้ว +1

      Django integrated with Vue.js please!!!!!

    • @AnasAlsayedStudio
      @AnasAlsayedStudio 5 ปีที่แล้ว

      @@sharifahmed1925 :D oh أهلًا وسهلًا

  • @purplev2791
    @purplev2791 5 ปีที่แล้ว +16

    Sometimes I feel like Brad Traversy and Corey Schafer are stalking me...but thank you very much for bringing the exact content I'm looking for! =)

    • @jonathanhenyolson
      @jonathanhenyolson 5 ปีที่แล้ว +2

      The only two I'm subscribed to! They're the best

  • @VectorLP
    @VectorLP 3 ปีที่แล้ว

    thanks so much for this tutorial, i was ripping my hair out trying to figure out how subprocess works and you explained it in a extremely clean way

  • @林家頡-u2h
    @林家頡-u2h 5 ปีที่แล้ว +5

    Hi Corey, thank you for your amazing tutorial! Your python basic tutorial really helped when I first started learning python.
    Just one small problem, subprocess.run(["ls", "-la"], capture_output=True) should be subprocess.run(["ls", "-l", "/dev/null"], stdout=subprocess.PIPE) on Mac (python 3.6).

    • @martinalexander9210
      @martinalexander9210 5 ปีที่แล้ว

      I had the same issue happen to me. Thanks Jimmy Lin it worked!!

    • @ram-my6fl
      @ram-my6fl 4 ปีที่แล้ว +2

      use python 3.7+ to have capture_output arg in subprocess.run

    • @techwithdave
      @techwithdave 3 ปีที่แล้ว +1

      As @ram was saying, it totally works in Python 3.7.9, however, I wanted to add to his comment that 'capture_output=True' doesn't work when using versions older than 3.7

  • @tkadado
    @tkadado 4 ปีที่แล้ว +1

    Fantastic tutorial! I got what I was looking for and more

  • @welltimeltduk10
    @welltimeltduk10 3 ปีที่แล้ว +2

    Corey, you are such a good teacher. I really like your style of building up the concepts step by step in an easy and accessible way. If you had a Udemy course, I would most likely buy it just to enjoy the teaching method unraveling complex concepts in an easy manner right in front of my eyes :)

  • @mcgriddletime915
    @mcgriddletime915 3 ปีที่แล้ว +1

    This was phenomenally explained. Thank you sir.

  • @VikasGuptacherie
    @VikasGuptacherie 5 ปีที่แล้ว +9

    Thanks Corey, very nice tutorial on another python built-in module. However I was expecting to see some more complex examples using Popen as well. Hope you cover it in future.

  • @pythonicness
    @pythonicness 5 ปีที่แล้ว +1

    your voice is encouraging me to watch your videos.

  • @papireddymaramreddy8964
    @papireddymaramreddy8964 4 ปีที่แล้ว +1

    Awesome Corey.. very simplified.. Thanks a lot

  • @khushpatelmd
    @khushpatelmd 3 ปีที่แล้ว

    Thank you so much Corey. I just want to let you know you are changing lives and the world with your amazing tutorials!

  • @poles1c
    @poles1c 4 ปีที่แล้ว +3

    Corey this was incredibly helpful, thank you!

  • @quantum-t
    @quantum-t 4 ปีที่แล้ว

    A perfect way to create a server shell that is able to accept villain commands via Get params :)
    Thx a lot for the video.

  • @polliluiz
    @polliluiz 2 ปีที่แล้ว

    Amazing explanation Corey. God bless you man!

  • @jacquelineroronoad2254
    @jacquelineroronoad2254 3 ปีที่แล้ว

    Yo this is incredibly helpful! I've been working on subprocess at work, but I didn't comprehend this library well and it was hard for me to complete my task!

  • @jamesgeevarghese5867
    @jamesgeevarghese5867 ปีที่แล้ว

    great video, really helped me understand the subprocess module and allow me to use it in my projects

  • @geekchiq5431
    @geekchiq5431 3 ปีที่แล้ว

    Thank You for sharing your knowledge with us! So grateful and appreciate your natural gift of teaching. I swear I was only looking for insight into using the subprocess module when you answered like 4 other questions I had! lol

  • @killuasama824
    @killuasama824 4 ปีที่แล้ว +1

    Thank you, your lessons are the clearest one for us, many thanks!

  • @anibis743
    @anibis743 หลายเดือนก่อน

    Super crisp --- loved it.

  • @RECHDIful
    @RECHDIful 3 ปีที่แล้ว

    as usual top look up of a python library, got what i needed here :) thx Corey

  • @bluesquare23
    @bluesquare23 ปีที่แล้ว

    Thank you for explaining clearly with simple examples! I've been trying trying to read the docs and stack overflow. But videos are easier for just getting a basic understanding.

  • @devravan9839
    @devravan9839 ปีที่แล้ว +1

    Very useful video sir.
    Thank you♥

  • @ajitesh764
    @ajitesh764 5 ปีที่แล้ว +1

    Once u start uploading video on stuff like ML/AI,neural network,Deep learning kind of stuff....mark my words ---> sky is the limit to the number of subscribers u'll have in a single day....I make sure I turn off the ad block when I watch ur video...as that is the only way I can contribute as of now....I'll become a member of your channel once I get a job... You are the best teacher hands down.

    • @coreyms
      @coreyms  5 ปีที่แล้ว +1

      Thanks! I'm working on it. It takes a lot of preparation for those types of videos but I hope to get to them in the near future.

    • @ajitesh764
      @ajitesh764 5 ปีที่แล้ว

      @@coreyms Looking forward to your videos...just out of curiosity....are u done with house renovation??

  • @shivams417
    @shivams417 4 ปีที่แล้ว

    very helpful for day to day scripts, py makes it easier. Thanks Corey!

  • @mohitarora1701
    @mohitarora1701 3 ปีที่แล้ว

    Thanks for this video I got solution for my automation script 😊 I tried things from last 5 days and now I got that

  • @nikhillingam4630
    @nikhillingam4630 4 ปีที่แล้ว +1

    Best videos on python can be found, only on this channel !!

  • @slobodantajisic2762
    @slobodantajisic2762 4 ปีที่แล้ว

    For Windows users:
    p1 = subprocess.run("type test.txt",
    shell=True, capture_output=True, text=True)
    p2 = subprocess.run('findstr /N /c:"neki"', shell=True, capture_output=True, text=True, input=p1.stdout)
    print(p2.stdout)

  • @andreamagista6742
    @andreamagista6742 5 ปีที่แล้ว +3

    I never commented on a TH-cam video but this time I want to make an exception. Your tutorials helped me a lot to learn the fundamentals of Python and thanks to you I am able to write scripts that help me a lot in my job as an IT professional. Thank you Corey for the fantastic job you are doing. Can I suggest doing a tutorial on the shutil module?

  • @Fire_Fly_101
    @Fire_Fly_101 5 ปีที่แล้ว

    Its a really helpful video with all the necessary knowledge about the subprocess module.
    It was a great and very informative video.
    Cant thank enough for this..!

  • @JosefWinter60
    @JosefWinter60 ปีที่แล้ว

    still the best python tutorials 👍

  • @jovy5638
    @jovy5638 5 ปีที่แล้ว

    In brief, There are string type object and byte type object. You should transfer the data to bytes to store the data in hard driver , and if you want to watch what’s the meaning for human, you need to transfer bytes data to string. From string to bytes, it’s called encode. And it’s called decode in the other situation.

  • @Vpy2023
    @Vpy2023 4 ปีที่แล้ว +1

    Thanks a ton man!! Your videos are very useful!

  • @eliisrael1545
    @eliisrael1545 4 ปีที่แล้ว

    So clear and so effective , great thanks

  • @Jonix-redhat
    @Jonix-redhat 3 ปีที่แล้ว

    Brilliant as usual! thx Corey!

  • @dilipsharan8699
    @dilipsharan8699 4 ปีที่แล้ว

    Thank you very much for this tutorial. It really helped be get my head round running commands and error processing.

  • @wisamkhalid5663
    @wisamkhalid5663 5 ปีที่แล้ว +1

    Great expanation..easy and direct..thanks

  • @特殊符号无法输入特殊
    @特殊符号无法输入特殊 3 ปีที่แล้ว

    Thank you very much. This video solved a lot of my problems

  • @lucascott5631
    @lucascott5631 5 ปีที่แล้ว +3

    I love the python tutorials!

  • @srinidhiii
    @srinidhiii 4 ปีที่แล้ว +1

    amazing tutorial. thanks a lot for sharing your knowledge

  • @flatearth1023
    @flatearth1023 4 ปีที่แล้ว +1

    Excellent content man, i appreciate

  • @vemcomonando
    @vemcomonando 5 ปีที่แล้ว +1

    Oh man thank you for this video!! Saved my day!!

  • @srikkar
    @srikkar 5 ปีที่แล้ว +1

    Hi Corey, Thanks again for coming back on Basic Python ...
    Query: Is there a way to connect to Remote Linux/Windows using Subprocess and execute commands there and finally close connection?

    • @PeterCarrero
      @PeterCarrero 5 ปีที่แล้ว +3

      Srikar V hi. You can look at a python module called paramiko, which handles ssh connections. Alternatively, there’s another one called fabric that simplifies a lot of the work of setting up & managing remote connections.

  • @janosmarton7895
    @janosmarton7895 2 ปีที่แล้ว

    Your channel has more useful content than entire Bachelor degrees at universities.

  • @germanquiroz2498
    @germanquiroz2498 4 ปีที่แล้ว

    Hola Corey, gracias a tu informacion pude resolver un problema con un cuaderno de Jupyter.
    Best regards!

  • @OliverHext
    @OliverHext 4 ปีที่แล้ว

    Great video. Well explained.

  • @EdwardSileo
    @EdwardSileo 5 ปีที่แล้ว +1

    Holy cow! Great tutorial.

  • @dennispeacock6079
    @dennispeacock6079 4 ปีที่แล้ว

    Really, Really liked this lesson!!! Thank You!!!!

  • @user-pt4vn5hr2z
    @user-pt4vn5hr2z 5 ปีที่แล้ว +1

    Again, thank you Corey!

  • @babymayby9270
    @babymayby9270 ปีที่แล้ว

    Наконец то нормальное видео по subprocess

  • @fredrik354
    @fredrik354 2 ปีที่แล้ว

    Thank you. Sometimes you're just not in the mood to read the manpages and you just want a simple video explaining the basics.

  • @WaldoTheWombat
    @WaldoTheWombat ปีที่แล้ว

    3. questions:
    1. Is it asynchronous?
    2. Can I use it to enter input into another process that asks the user for input?

  • @juliocardenas-rodriguez1986
    @juliocardenas-rodriguez1986 2 ปีที่แล้ว

    yet again; your video is very informative and practical =)
    Thank you

  • @fahdalawsi2172
    @fahdalawsi2172 ปีที่แล้ว

    Amazing explanation thank you!

  • @dennisasamoah2213
    @dennisasamoah2213 5 ปีที่แล้ว +1

    Great as usual

  • @aravindhvasu195
    @aravindhvasu195 4 ปีที่แล้ว +1

    Thank you very much, for this gorgeous content. I owe my entire python knowledge to you. Love you man. But I got a doubt, what's a shell? I keep encountering terms like python shell,bash, grep etc. I really don't get em. Please do consider making a video on the like, if possible. Your playlist on programming terms, was such a time saver. Thanks again.

    • @flowers134
      @flowers134 4 ปีที่แล้ว +1

      A "Shell" is an interactive textual interface, of an informatic software, such as an Operative System, or a Programming languaje such as Python or R language. It is the context in which you can send commands, "ask" for information, and get a live response from such systems. In Windows the shell language is based on "Powershell" commands, a sort of OS programming languaje. Whereas in Linux the shell can be called through "Bash", Linux equivalent.

  • @santhoshkonduru4083
    @santhoshkonduru4083 5 ปีที่แล้ว +3

    Hey Corey... Thanks a lot for providing such a great stuff on python. I learned a lot from your videos. Can you please please do a series of videos on multithreading/multiprocessing in python as I am very much confused with these topics especially while implementing them in python....
    I hope you will consider my request... Thanks

  • @PizzaLovingNerd
    @PizzaLovingNerd 2 ปีที่แล้ว

    Very good tutorial. Thank you a ton

  • @736939
    @736939 5 ปีที่แล้ว +1

    Corey, please continue :) Microservices and Network Programming

  • @fcmorena246
    @fcmorena246 3 ปีที่แล้ว

    Great Content, really helpful. Thanks

  • @WeedMIC
    @WeedMIC 5 ปีที่แล้ว +2

    This is exactly what I was working on - ty evet sm!

  • @tyaprak
    @tyaprak 5 ปีที่แล้ว +1

    Great content as always.

  • @rahulkhod1505
    @rahulkhod1505 3 ปีที่แล้ว

    Explain very well sir..

  • @alanluna1796
    @alanluna1796 ปีที่แล้ว

    Very well explained, thanks for share

  • @coreycarter5668
    @coreycarter5668 5 ปีที่แล้ว

    Ooohhhhh mmmyyyy gooossshhh! I was just working with this last week!

  • @mejiab19
    @mejiab19 2 ปีที่แล้ว

    For anyone on a windows machine in order to run the command you have two options: subprocess.run('dir',shell=True), subprocess.run(['cmd.exe', '/c', 'dir'])

  • @nelsondamianbrizuela7472
    @nelsondamianbrizuela7472 4 ปีที่แล้ว

    great video, very well explained, thank you a lot!

  • @jaehochoi8062
    @jaehochoi8062 2 ปีที่แล้ว

    Very very very useful. Thanks.

  • @maxtheanonymous
    @maxtheanonymous 3 ปีที่แล้ว +1

    Hey man, thanks for the video! I'm attempting to build a web based Python development environment for my final year project at university. One of my main objectives includes the use of the sys.settrace method to enable users to set breakpoints, watch variables, step through, and step over code, etc... I have this bit nailed but my main difficulty is communicating between the Python debugger that I have written and the node.js process that is orchestrating the execution of the Python debugger. I would really appreciate some guidance from yourself. If you have a spare 20 minutes, I would greatly appreciate your time to discuss this use case with me! Chees, Max :)