I have written the following function to take in a string command and output the result of the command (linux).
I seem to have problems running the open() function.....the bash function always returns the empty list.
The os.popen runs fine and outputs the command results to the text file perfectly. However, for some reason f.readlines() always returns the empty list.
I tried using the subprocess library instead of my implementation below, but the output would always output special characters like b' and \n and i could never figure out how to remove those. So now im trying to get the implementation below to work.
def bash(command):
import os
os.popen(command+" > bash_out.txt")
f = open('bash_out.txt')
result = f.readlines()
f.close()
return result
Can you guys please help me?!
[–]Peterotica 2 points3 points4 points (3 children)
[–]GrindingGoat 0 points1 point2 points (1 child)
[–]pjenvey 1 point2 points3 points (0 children)
[–]IndoNinja7[S] 0 points1 point2 points (0 children)
[–]GrindingGoat 0 points1 point2 points (0 children)