Running Shell Commands using Python (Detailed Explanation)

Поділитися
Вставка
  • Опубліковано 23 гру 2024

КОМЕНТАРІ • 60

  • @IndianPythonista
    @IndianPythonista  4 роки тому +7

    Code: gist.github.com/nikhilkumarsingh/c23fbd592b4268f225cb895afaa187fe
    2:32 Old methods of running shell commands (os.system, os.popen, os.spawn)
    7:25 Introduction to subprocess module
    11:05 Run command and read output
    15:43 Run command by passing single string (shell parameter)
    16:40 Security considerations while using shell paramter
    22:58 Run command and pass input
    26:50 Run command with timeout
    27:56 Run command and throw error if fail

    • @amandubey7430
      @amandubey7430 3 роки тому

      how do I edit files(files like cat/etc/hosts or etc/selinux/config (the things that we can edit using vim or nano on terminal)) by using python(like i run the .py file in terminal and that file gets edited instead of me manually editing it) pls help if someone has any clue, or pls give me videos/ links related to this if anyone knows. need help

    • @mang0U_018
      @mang0U_018 3 роки тому

      How can i run command = (New-Object -com "WMPlayer.OCX.7").cdromcollection.item(0) in powershell using python.
      Please help..

  • @futuregootecks
    @futuregootecks 2 роки тому

    Wow that was so helpful!! I didn’t realize how straightforward it could be with the subprocess module.
    I was so overwhelmed I tried to just write a bash script instead to run shell commands but that ended up taking forever because my bash skills aren’t that good yet.
    Thanks and Keep up the great work!

  • @kapilsonyt
    @kapilsonyt 4 роки тому +5

    You are an amazing person. Thats what I was looking for. Thank you Sir!

  • @utkarshshrivastava7468
    @utkarshshrivastava7468 4 роки тому +3

    is there any way to run multiple shell commands in the same process instance? like reusing Popen?

  • @prateeksarangi9187
    @prateeksarangi9187 2 роки тому

    keep making these video mate !! content is superb

  • @makingachanneltopost
    @makingachanneltopost 4 роки тому +11

    Nice video! Quick note, shell is '/bin/sh', not '/usr/sh' :-)

  • @nson22
    @nson22 3 роки тому +1

    You helped me so much with my scripts

  • @DhimanGhoshYT
    @DhimanGhoshYT 2 роки тому

    My doubt is suppose I have a bat/shell script file that accepts multiple user inputs... So how can we execute this bat file from the python script and even handle/automate the user inputs from python script itself?

  • @fstreamdl1631
    @fstreamdl1631 Рік тому

    Hey Bro what if the shell command I am executing does need another input in the middle of processing. Like it needs to press Y/N to confirm the execution.
    How can i do this.

  • @anonnewuserp9530
    @anonnewuserp9530 4 роки тому +1

    Hi Nikhil, your tutorials are very informative. Thanks for uploading!

  • @balbinodejesus8175
    @balbinodejesus8175 3 роки тому +1

    Very, very, Very good!
    Thank you Very much!

  • @amangoyal1288
    @amangoyal1288 Рік тому

    Hi, I am getting error in using this subprocess to open the hostapd file in terminal of rasbian software. I am getting the error " Too many errors from stdin "

  • @gopalsaraf5097
    @gopalsaraf5097 3 роки тому

    Is there any way to get live output like rclone copy progress???

  • @prashanabalaji7594
    @prashanabalaji7594 2 роки тому

    I have echo $1 in my shell script...I am trying to pass Hello as parameter/ input from python script.Any idea

  • @axosolaman8984
    @axosolaman8984 2 роки тому

    Bro faceing issue
    subprocess' has no attribute 'run
    how to fix it

  • @prateeksarangi9187
    @prateeksarangi9187 2 роки тому

    Thanks a lot !! Mate !! Learned so much from you

  • @yeswanthkumar1434
    @yeswanthkumar1434 2 роки тому

    How to awk command in python , I tried using it with subprocess but getting below error .
    awk is not recognised as an internal or external command .

  • @devinpython5555
    @devinpython5555 3 роки тому

    Say I am in file abc.py and need to open command prompt from abc.py and pass new path and new command to newly opened command prompt, how do I do this?

  • @KiranKumar-zb6ly
    @KiranKumar-zb6ly 3 роки тому

    HI sir i want to get version of powershell by using python script. can you help me?

  • @hirakhax
    @hirakhax 2 роки тому

    os kya hei bro? And what is the theme ?

  • @SapnaSaini3
    @SapnaSaini3 4 роки тому +2

    This was an easy and amazing video . Thank you for putting it here

  • @anton-r
    @anton-r 2 роки тому

    gret lesson , super tnx you 😀

  • @benlahav3779
    @benlahav3779 3 роки тому

    Great overview on the subject..

  • @axosolaman8984
    @axosolaman8984 2 роки тому

    Thanks for this video love you brother

  • @iwswordpress
    @iwswordpress 7 місяців тому

    Very useful, Thanks

  • @wesg01
    @wesg01 2 роки тому

    Very nice! Thanks

  • @grumpy_techo
    @grumpy_techo 3 роки тому

    Nice useful video - thanks for making this available

  • @Arunkumar-jz9ry
    @Arunkumar-jz9ry 3 роки тому

    Awesome Explanation

  • @alagarsamy3079
    @alagarsamy3079 4 роки тому

    Is there any way to run commands in to and fro manner from python code to command line?

  • @durgaganesh423
    @durgaganesh423 3 роки тому

    Hi how run command as administrator in python script

  • @srinivaskalwad2309
    @srinivaskalwad2309 2 роки тому

    Hi this video was so interesting. I have stuck in one of the issue while using this run with minicom.
    problem : running this command ["minicom", "-D", "/dev/ttyUSB1"] after this i will turn on device that will start booting for 30 secs and it will ask for inputs. how to do that?
    is running commands once minicom triggered is it possible?

  • @Alpha-0101
    @Alpha-0101 4 роки тому +1

    Great Bro ❤️

  • @yatanik
    @yatanik 3 роки тому

    How to run an program which has a infinite while loop or application such as iperf server and client way to kill the process

  • @sarahpes32
    @sarahpes32 3 роки тому +1

    Amazing!! thank you alot!

  • @vanitymeetstechnology8792
    @vanitymeetstechnology8792 2 роки тому

    Thanks for the video friend... can you do more of these which are used in Production, like for Linux Admin tasks

  • @yairzak
    @yairzak 4 роки тому

    what distro are you using/ desktop enviroment

  • @jackeyzhu3702
    @jackeyzhu3702 3 роки тому

    perfect vid! at the very end of the vid, you showed how to check if there is an error. I'm wondering how to not only check for error but also what specifically the error is about. How would you recommend doing it?

  • @Gold_fi
    @Gold_fi 4 роки тому +1

    I 've just subbed pls do more videos like this

  • @SushmaSingh-le1iw
    @SushmaSingh-le1iw 4 роки тому

    can you make the video for reading the dictionary by key to get value using shell command in python

  • @NageshGandewar
    @NageshGandewar 4 роки тому

    Hi sir, need help for python coding. Where can I contact you?

  • @vivekdabholkar5965
    @vivekdabholkar5965 2 роки тому

    #p = subprocess.run(["python3", "universal.py"],shell=True,capture_output=True,input='SP600-6')
    #p = subprocess.run(["python3", "universal.py"],capture_output=True,input="SP600-6".encode(), text=True)
    p = subprocess.run(["python3", "universal.py"],capture_output=True, stdin=open("a.txt",'r'))
    None of the above work? What am I doing wrong on windows machine?

  • @fredericoisaac9074
    @fredericoisaac9074 3 роки тому

    Thank you so much, i what i was looking for

  • @klustereman3749
    @klustereman3749 4 роки тому

    Can u make a tutorial of making a simple gui application, which runs cmd commands

  • @TheZielony20
    @TheZielony20 2 роки тому

    Thank you!

  • @amandubey7430
    @amandubey7430 3 роки тому

    how do I edit files(files like cat/etc/hosts or etc/selinux/config (the things that we can edit using vim or nano on terminal)) by using python(like i run the .py file in terminal and that file gets edited instead of me manually editing it) pls help if someone has any clue, or pls give me videos/ links related to this if anyone knows. need help

  • @alythesniper2737
    @alythesniper2737 3 роки тому

    Great vid, Thanks alot

  • @durgaganesh423
    @durgaganesh423 3 роки тому

    How to run command as administrator with python script

  • @sealandland3959
    @sealandland3959 2 роки тому

    Could you do a version in English?

  • @shelly1067
    @shelly1067 3 роки тому

    Thank you 🙏

  • @shreyasb.s3819
    @shreyasb.s3819 3 роки тому

    Nice

  • @wlqpqpqlqmwnhssisjw6055
    @wlqpqpqlqmwnhssisjw6055 4 роки тому

    congratulations I found you

  • @ayushsuman001
    @ayushsuman001 4 роки тому

    👍