Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is parameter that i want to run:

cd ../linux-3.11/; cp arch/x86/configs/byt_32_tz_emgd_defconfig .config; make ARCH=i386 oldconfig; make ARCH=i386 -j 4

I want this to save to bash file using python. I want it run exactly as user input into linux command (without semicolon) because of path issue.

Please provide me some simple example how create bash file and run it in python script.

share|improve this question
add comment

1 Answer

No need to save it to a file, just run it in a subprocess:

import os
os.system("""cd ../linux-3.11/; cp arch/x86/configs/byt_32_tz_emgd_defconfig .config; make ARCH=i386 oldconfig; make ARCH=i386 -j 4""")

You can use subprocess if you want to do input/output into the subprocess. One trick I really like is making your script script.ipy with a shebang of #!/usr/bin/ipython. Then you can use ! to run bash commands. I haven't seen many other people do this but it's awefully convenient.

share|improve this answer
 
Thanks for this tip, but it not exactly what I want, can you provide me how to create and run bash file using python? its because I using variable parameters. –  azmilhafiz 2 mins ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.