run .sh file from python spyder in windows

Multi tool use
Multi tool use


run .sh file from python spyder in windows



Please help me to run .sh file (bash file) from Python Spyder IDE in windows. I am using the below code.


.sh


import subprocess
subprocess.call(['./test.sh'])



I am facing the error:


FileNotFoundError: [WinError 2] The system cannot find the file specified



I do not know where I have to keep test.sh file in windows.


test.sh



enter image description here





I'm not sure there is going to be any easy way to run a shell script file on Windows (from Python or otherwise), since you probably don't have a Unix shell program available to run it.
– Blckknght
Jul 1 at 17:18





How about just rewriting the shell script into Python?
– cricket_007
Jul 2 at 5:43




1 Answer
1



change dir while calling the test.sh file :


change dir


test.sh



First, install Git (https://git-scm.com/downloads)


>>> import os
>>> from subprocess import Popen,PIPE
>>> os.chdir("path of test.sh file")
>>> p = Popen(["filename"], shell=True, stdout = PIPE)



There is some security consideration plz read this:



(Using subprocess.Popen to run a batch file in Windows)



and read comment session also





Thanks for your reply.I did the same but it is not working for me.Have you tried to do the same in windows?
– ankit jain
Jul 2 at 4:20





Ya it worked for me
– Hitesh_Gorana
Jul 2 at 4:45





Now I am getting error: OSError: [WinError 193] %1 is not a valid Win32 application
– ankit jain
Jul 2 at 5:04






i am editing my answer
– Hitesh_Gorana
Jul 2 at 5:31





you should have` git bash` installed
– Hitesh_Gorana
Jul 2 at 5:38






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

MBJgjXQ5ravMIR05cT3Ou,hSe3J k,D3V9sjBISSTn2Yar853dj,NmQD4U
5E jNY2bjYo0dCm6j,77,lAb8hLpGxCoNZ,kYf7 j6QfsA602i,S4Ym4mOM,Db7Ghk,TztX8,lVvkzBUN2ikq,6u gpgflULr pSNpIT,0

Popular posts from this blog

Rothschild family

Boo (programming language)