Answers for "python read command"

29

python get command line arguments

import sys
print("This is the name of the script:", sys.argv[0])
print("Number of arguments:", len(sys.argv))
print("The arguments are:" , str(sys.argv))

#Example output
#This is the name of the script: sysargv.py
#Number of arguments in: 3
#The arguments are: ['sysargv.py', 'arg1', 'arg2']
Posted by: Guest on March-08-2020
0

python on read text execute command

import subprocess

# read in users and strip the newlines
with open('/tmp/users.txt') as f:
    userlist = [line.rstrip() for line in f]

# get list of commands for each user
cmds = []
for user in userlist:
    cmds.append('smbmap -u {} -p p@ssw0rd -H 192.168.2.10'.format(user))

# results from the commands
results=[]

# execute the commands
for cmd in cmds:
    results.append(subprocess.call(cmd, shell=True))

# check for which worked
for i,result in enumerate(results):
    if result == 0:
        print(cmds[i])
Posted by: Guest on January-18-2021

Code answers related to "python read command"

Python Answers by Framework

Browse Popular Code Answers by Language