How I can interaction with linux console in python. Open (or not) window with console, and do any command or just typing something and press enter
            Asked
            
        
        
            Active
            
        
            Viewed 52 times
        
    2 Answers
0
            I like to use both subprocess and os.
These python modules dont necessarily 'open a console and run a command' rather they interface with your shell.
import os
import subprocess
eg
fileCount = int(subprocess.check_output('ls dir/ | wc -l', shell=True).decode().strip())
or
pathToOldest = './someDir/' + oldestFileInDir
os.remove(pathToOldest)
If youre looking to do run a particular command I would go to a search engine and type 'python run shell commmands' or 'run {enter shell command} in pythonX}
 
    
    
        Kevin Crum
        
- 195
- 2
- 16
- 
                    1https://stackoverflow.com/questions/4760215/running-shell-command-and-capturing-the-output – kira Dec 31 '20 at 02:29
 
    