Python Forum
Linux command output not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linux command output not working
#1
Hi guys,

I am working on a network analysis tool for a project in college, I am using airodump-ng to find all networks in the general area,

when I run the following command airodump-ng wlan0 --write tempfile --output-format' in the python script nothing gets created but when I run it manually a csv file with the output will be created

from subprocess import Popen,PIPE
import sys,os
import csv        

        def execute_command(command):
        process = Popen(command,stdout=PIPE,stder=PIPE)
        return process.communicate()


tempfile = "\root\Desktop\networks
# instance of WPA class test_WPA created, only execute_command method is of relevance


out,err = test_WPA.execute_command(['airodump-ng','wlan0','--write',tempfile,'--output-format','csv'])

it does seem to be working now after I put my wireless card in

I changed the code a bit and made airodump-ng run in another thread

command = ['airodump-ng','wlan0','--write',tempfile,'--output-format','csv']
thread = threading.Thread(target= test_WPA.execute_command,args= (command, ))
thread.start()
thread.join(1)
the great thing it now creates the file, but the the process remains open I want the airodump-ng(thread) to stop running after 30 seconds, should set thread to be a daemon thread?? or is there another way I can get airodump to stop running after 30 seconds?

thanks
Reply
#2
No threads needed

import time


def execute_command(command):
        process = Popen(command,stdout=PIPE,stder=PIPE)
        time.sleep(10)
        process.terminate()
The call communicate blocks until the process has been finished.
If you don't terminate the process, then it's running in the background and does not block.
In the case of a long running background process, you should return proc in your function.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
thanks DeadEye

to get the output could I still do vv

  
  time.sleep(10)
  stdout,stderr = process.communicate()
  process.terminate()
  return stdout,stderr
this way I can still get the output from process.communicate() and return stdout and stderr respective outputs and also terminate the process
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is possible to run the python command to call python script on linux? cuten222 6 633 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,034 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  Os command output in variable shows wrong value paulo79 2 1,467 Apr-09-2022, 03:48 PM
Last Post: ndc85430
  How to use a variable in linux command in python code? ilknurg 2 1,547 Mar-14-2022, 07:21 AM
Last Post: ndc85430
  use subprocess on linux\pi wwith a "grep " command korenron 2 7,906 Oct-19-2021, 10:52 AM
Last Post: DeaD_EyE
  Command output to Variable ironclaw 1 1,743 Aug-26-2021, 06:55 PM
Last Post: bowlofred
  How to input & output parameters from command line argument shantanu97 1 2,507 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  how to run linux command with multi pipes by python !! evilcode1 2 6,219 Jan-25-2021, 11:19 AM
Last Post: DeaD_EyE
  Print output not working xninhox 7 3,942 Jan-16-2021, 09:42 AM
Last Post: xninhox
  Subprocess command working for one cmd and for cmd one not wrking PythonBeginner_2020 0 4,105 Mar-25-2020, 01:52 PM
Last Post: PythonBeginner_2020

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020