How to use subprocess to run linux commands in python file before other python code and use the output of subprocess for the next processing?How do I copy a file in Python?How do I check what version of Python is running my script?How to check file size in python?How to import other Python files?Constantly print Subprocess output while process is runningHow do you append to a file in Python?Running shell command and capturing the outputHow to move a file in PythonWhy does Python code run faster in a function?How to hide output of subprocess in Python 2.7

Why does string strummed with finger sound different from the one strummed with pick?

pwaS eht tirsf dna tasl setterl fo hace dorw

Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?

Is it a good idea to teach algorithm courses using pseudocode?

Driving a school bus in the USA

on the truth quest vs in the quest for truth

Former Employer just sent me an IP Agreement

How to get all possible paths in 0/1 matrix better way?

Why does the U.S military use mercenaries?

Was Tyrion always a poor strategist?

How does this piece of code determine array size without using sizeof( )?

How was the blinking terminal cursor invented?

Appropriate liquid/solvent for life in my underground environment on Venus

Can ThermodynamicData be used with NSolve?

In Dutch history two people are referred to as "William III"; are there any more cases where this happens?

Cycling to work - 30mile return

FIFO data structure in pure C

Have the writers and actors of GOT responded to its poor reception?

How come Arya Stark wasn't hurt by this in Game of Thrones Season 8 Episode 5?

Why is choosing a suitable thermodynamic potential important?

Combining two Lorentz boosts

Have GoT's showrunners reacted to the poor reception of the final season?

How can I monitor the bulk API limit?

Why does Taylor’s series “work”?



How to use subprocess to run linux commands in python file before other python code and use the output of subprocess for the next processing?


How do I copy a file in Python?How do I check what version of Python is running my script?How to check file size in python?How to import other Python files?Constantly print Subprocess output while process is runningHow do you append to a file in Python?Running shell command and capturing the outputHow to move a file in PythonWhy does Python code run faster in a function?How to hide output of subprocess in Python 2.7






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I want to run linux commands first then What want to use that capture-csv file result from those commands for further processing in code below those commands.



import requests
import csv
import pandas as pd
import os
import sys
import subprocess


subprocess.run(["iw","phy","phy0","interface","add","mon0","type","monitor"]) ##these three commands return csv file named capture-csv-01
subprocess.run(["ifconfig","mon0","up"])
subprocess.run(["airodump-ng","-w","capture.csv","mon0"])

with open('/root/Desktop/Python-3.6.5/capture.csv-01.csv' ) as f: ## open csv file
s = f.read().split('nn') ## split file in two files using dataframes on the basis of empty line
df1=pd.read_csv(pd.compat.StringIO(s[0]))
df2=pd.read_csv(pd.compat.StringIO(s[1]))
## df2.info()
## df2.drop(df2.columns[[4]],axis=1,inplace=True)
for index,row in df2.iterrows(): ## read each value of each column
Station_MAC= (row["Station MAC"])
First_time_seen=(row[" First time seen"])
Last_time_seen=(row[" Last time seen"])
Power=(row[" Power"])
Packets=(row[" # packets"])
BSSID=(row[" BSSID"])
Probed_ESSIDs=(row[" Probed ESSIDs"])
print(Station_MAC,First_time_seen,Last_time_seen,Power,Packets,BSSID,Probed_ESSIDs)
##code to send data to database
url = "http://10.5.9.162/api/customers_data/create.php"
headers =
'cache-control': "no-cache",
'Postman-Token': "ca64cf56-19e8-4e6c-85a7-1741355ced79"

payload = '"Station_MAC": "'+str(Station_MAC)+'","First_time_seen": "'+str(First_time_seen)+'","Last_time_seen": "'+str(Last_time_seen)+'","Power": "'+str(Power)+'","Packets":"'+str(Packets)+'","BSSID": "'+str(BSSID)+'","Probed_ESSIDs": "'+str(Probed_ESSIDs)+'"'
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)


When I run subprocesses and code below the subprocess commands separately in separate python files I get what i want. But when I write them in one file only above three lines run nad give csv file in result and then nothing happen. How I can do this.?










share|improve this question






























    0















    I want to run linux commands first then What want to use that capture-csv file result from those commands for further processing in code below those commands.



    import requests
    import csv
    import pandas as pd
    import os
    import sys
    import subprocess


    subprocess.run(["iw","phy","phy0","interface","add","mon0","type","monitor"]) ##these three commands return csv file named capture-csv-01
    subprocess.run(["ifconfig","mon0","up"])
    subprocess.run(["airodump-ng","-w","capture.csv","mon0"])

    with open('/root/Desktop/Python-3.6.5/capture.csv-01.csv' ) as f: ## open csv file
    s = f.read().split('nn') ## split file in two files using dataframes on the basis of empty line
    df1=pd.read_csv(pd.compat.StringIO(s[0]))
    df2=pd.read_csv(pd.compat.StringIO(s[1]))
    ## df2.info()
    ## df2.drop(df2.columns[[4]],axis=1,inplace=True)
    for index,row in df2.iterrows(): ## read each value of each column
    Station_MAC= (row["Station MAC"])
    First_time_seen=(row[" First time seen"])
    Last_time_seen=(row[" Last time seen"])
    Power=(row[" Power"])
    Packets=(row[" # packets"])
    BSSID=(row[" BSSID"])
    Probed_ESSIDs=(row[" Probed ESSIDs"])
    print(Station_MAC,First_time_seen,Last_time_seen,Power,Packets,BSSID,Probed_ESSIDs)
    ##code to send data to database
    url = "http://10.5.9.162/api/customers_data/create.php"
    headers =
    'cache-control': "no-cache",
    'Postman-Token': "ca64cf56-19e8-4e6c-85a7-1741355ced79"

    payload = '"Station_MAC": "'+str(Station_MAC)+'","First_time_seen": "'+str(First_time_seen)+'","Last_time_seen": "'+str(Last_time_seen)+'","Power": "'+str(Power)+'","Packets":"'+str(Packets)+'","BSSID": "'+str(BSSID)+'","Probed_ESSIDs": "'+str(Probed_ESSIDs)+'"'
    response = requests.request("POST", url, data=payload, headers=headers)
    print(response.text)


    When I run subprocesses and code below the subprocess commands separately in separate python files I get what i want. But when I write them in one file only above three lines run nad give csv file in result and then nothing happen. How I can do this.?










    share|improve this question


























      0












      0








      0








      I want to run linux commands first then What want to use that capture-csv file result from those commands for further processing in code below those commands.



      import requests
      import csv
      import pandas as pd
      import os
      import sys
      import subprocess


      subprocess.run(["iw","phy","phy0","interface","add","mon0","type","monitor"]) ##these three commands return csv file named capture-csv-01
      subprocess.run(["ifconfig","mon0","up"])
      subprocess.run(["airodump-ng","-w","capture.csv","mon0"])

      with open('/root/Desktop/Python-3.6.5/capture.csv-01.csv' ) as f: ## open csv file
      s = f.read().split('nn') ## split file in two files using dataframes on the basis of empty line
      df1=pd.read_csv(pd.compat.StringIO(s[0]))
      df2=pd.read_csv(pd.compat.StringIO(s[1]))
      ## df2.info()
      ## df2.drop(df2.columns[[4]],axis=1,inplace=True)
      for index,row in df2.iterrows(): ## read each value of each column
      Station_MAC= (row["Station MAC"])
      First_time_seen=(row[" First time seen"])
      Last_time_seen=(row[" Last time seen"])
      Power=(row[" Power"])
      Packets=(row[" # packets"])
      BSSID=(row[" BSSID"])
      Probed_ESSIDs=(row[" Probed ESSIDs"])
      print(Station_MAC,First_time_seen,Last_time_seen,Power,Packets,BSSID,Probed_ESSIDs)
      ##code to send data to database
      url = "http://10.5.9.162/api/customers_data/create.php"
      headers =
      'cache-control': "no-cache",
      'Postman-Token': "ca64cf56-19e8-4e6c-85a7-1741355ced79"

      payload = '"Station_MAC": "'+str(Station_MAC)+'","First_time_seen": "'+str(First_time_seen)+'","Last_time_seen": "'+str(Last_time_seen)+'","Power": "'+str(Power)+'","Packets":"'+str(Packets)+'","BSSID": "'+str(BSSID)+'","Probed_ESSIDs": "'+str(Probed_ESSIDs)+'"'
      response = requests.request("POST", url, data=payload, headers=headers)
      print(response.text)


      When I run subprocesses and code below the subprocess commands separately in separate python files I get what i want. But when I write them in one file only above three lines run nad give csv file in result and then nothing happen. How I can do this.?










      share|improve this question
















      I want to run linux commands first then What want to use that capture-csv file result from those commands for further processing in code below those commands.



      import requests
      import csv
      import pandas as pd
      import os
      import sys
      import subprocess


      subprocess.run(["iw","phy","phy0","interface","add","mon0","type","monitor"]) ##these three commands return csv file named capture-csv-01
      subprocess.run(["ifconfig","mon0","up"])
      subprocess.run(["airodump-ng","-w","capture.csv","mon0"])

      with open('/root/Desktop/Python-3.6.5/capture.csv-01.csv' ) as f: ## open csv file
      s = f.read().split('nn') ## split file in two files using dataframes on the basis of empty line
      df1=pd.read_csv(pd.compat.StringIO(s[0]))
      df2=pd.read_csv(pd.compat.StringIO(s[1]))
      ## df2.info()
      ## df2.drop(df2.columns[[4]],axis=1,inplace=True)
      for index,row in df2.iterrows(): ## read each value of each column
      Station_MAC= (row["Station MAC"])
      First_time_seen=(row[" First time seen"])
      Last_time_seen=(row[" Last time seen"])
      Power=(row[" Power"])
      Packets=(row[" # packets"])
      BSSID=(row[" BSSID"])
      Probed_ESSIDs=(row[" Probed ESSIDs"])
      print(Station_MAC,First_time_seen,Last_time_seen,Power,Packets,BSSID,Probed_ESSIDs)
      ##code to send data to database
      url = "http://10.5.9.162/api/customers_data/create.php"
      headers =
      'cache-control': "no-cache",
      'Postman-Token': "ca64cf56-19e8-4e6c-85a7-1741355ced79"

      payload = '"Station_MAC": "'+str(Station_MAC)+'","First_time_seen": "'+str(First_time_seen)+'","Last_time_seen": "'+str(Last_time_seen)+'","Power": "'+str(Power)+'","Packets":"'+str(Packets)+'","BSSID": "'+str(BSSID)+'","Probed_ESSIDs": "'+str(Probed_ESSIDs)+'"'
      response = requests.request("POST", url, data=payload, headers=headers)
      print(response.text)


      When I run subprocesses and code below the subprocess commands separately in separate python files I get what i want. But when I write them in one file only above three lines run nad give csv file in result and then nothing happen. How I can do this.?







      python python-3.x python-requests subprocess delay






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 17:28









      πάντα ῥεῖ

      74.9k1078147




      74.9k1078147










      asked Mar 23 at 17:07









      AsmaAsma

      75




      75






















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316268%2fhow-to-use-subprocess-to-run-linux-commands-in-python-file-before-other-python-c%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55316268%2fhow-to-use-subprocess-to-run-linux-commands-in-python-file-before-other-python-c%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

          밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

          1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴