My question is similar to the one asked here. But the proposed solution is not working for what I am trying to do.
I am using Windows 10 with python 3.8.5. I am trying to run a cmd file which is stored in the network drive. But for that I dont want to use the path "Z:abcdefghi" instead I want to use "\ipabcdefghi". I tried using os.chdir("\ipabcdefghi") and check the directory I am in and it shows me exactly the path I enter. But when I try to run the file it says "returned non-zero exit status 1".
Here is a sample operation that I want to do;
First I tried this,
local_network_dir = "Z:\abc\def\ghi"
curr_dir = os.getcwd()
os.chdir(local_network_dir)
Works perfectly fine. But as I said I want to avoid this.
Then I tried this,
network_dir = "\\ip\abc\def\ghi"
local_output = subprocess.check_output('my_cmd_file -arg')
network_output = subprocess.check_output('pushd '+ key+ ' & ' + command + ' & popd',stderr=subprocess.STDOUT,shell=True)
This method works for me most of the time but sometimes fails so I want to avoid it.
Is there a way to make this robust so it doesnt fail ever?
question from:
https://stackoverflow.com/questions/65830343/using-pushd-and-popd-to-work-with-network-directories-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…