ฉันทำงานกับระบบลินุกซ์
ฉันมีโฟลเดอร์ที่แตกต่างกันมากมาย แต่ละโฟลเดอร์มีไฟล์ bash (ไฟล์ bash นั้นเท่ากันในแต่ละโฟลเดอร์) ไฟล์ bash นี้รันคำสั่งง่ายๆ เช่น โหลดสภาพแวดล้อม สร้างไฟล์และโฟลเดอร์ เพื่อรันแอปพลิเคชันไบนารี (เช่น code1)
จากโฟลเดอร์เหล่านี้มีไฟล์หลามซึ่งฉันต้องการเรียกใช้ baseFolder/myPython.py " folder1/myBash " folder2/myBash . . " โฟลเดอร์N/myBash
ปัญหา: เมื่อฉันรันสคริปต์ python (เช่น code2) ไฟล์ bash จะไม่ถูกดำเนินการภายในโฟลเดอร์ มันจะถูกดำเนินการเนื่องจากไฟล์ bash อยู่ใน baseFoldes ดังนั้นมันจึงสร้างโฟลเดอร์ ไฟล์ ฯลฯ ภายใน baseFolder ฉันไม่เข้าใจว่าทำไม
ฉันใช้แพ็คเกจระบบปฏิบัติการและกระบวนการย่อย:
os.system('shell command')
subprocess.run('shell command')
subprocess.call('shell command')
รหัส1
#!/bin/bash
mkdir myNewFolder
touch myNewFile
รหัส2
#!/usr/bin/env python3
import os
import subprocess
... other code ...
subprocess.run(fullPathFolder+"/myBash")
Or
subprocess.call(fullPathFolder+"/myBash")
Or
os.system(fullPathFolder+"/myBash")
baseFolder/myPython.py
" myNewFolder <<<<<<<<<<?????
" myNewFile <<<<<<<<<<?????
" folder1/myBash
" folder2/myBash
.
.
.
" folderN/myBash