1

I want to use a variable and pass it on to shell command line. Problem is. I don't know how. Need help.

 def gauti():
    imti=tekstas.get("1.0", "end-1c")
    subprocess.call("grep -i 'imti' /var/log/syslog > logas.txt", shell=True)

Instead of 'imti' I need a variable that would be delivered in python program to be searched in syslog file.

1 Answer 1

1

Use string formatting

subprocess.call("grep -i '{imti}' /var/log/syslog > logas.txt".format(imti=imti), 
                shell=True)

or pass array to call method with all required parts

logas = open('logas.txt', 'a+')
subprocess.call(['grep', '-i', imti, '/var/log/syslog'], stdout=logas)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.