【发布时间】:2016-12-11 19:35:39
【问题描述】:
我对 python 世界有点陌生,我在运行 bash 文件时遇到了一些问题,该文件将自动从我的 python 脚本(使用 linux)。
我将我的 python 脚本设置为在我的桌面某处的目录中创建一个文本文件 .geo 和一个 Bash 文件 .sh,如下所示:
basedirectory="/home/pst2/Desktop/";
*//Writing the .geo file*
file = open(basedirectory+nomdossier+"/"+nomfichier+".geo", 'w');
file.write
..blabla
..blabla
file.close();
//Writing the .sh file
file = open(basedirectory+nomdossier+"/"+nomfichier+".sh", 'w');
file.write
..blabla
..blabla
file.close();
现在,我的脚本与所有设置的变量完美配合,工作正常,我创建的两个文件都在这个目录中(例如在运行 python 脚本并输入变量之后)
/home/pst2/Desktop/test/
(and in here you will find the new test.geo and test.sh that were created via the python script)
基本上,当使用 Bash test.sh“手动”执行时 test.sh(每当我在 ubuntu 上的目录中时)将在同一目录中创建另一个名为 test.msh 的文件 而且我似乎找不到正确的编码,使用子进程模块从脚本自动执行新创建的 test.sh 文件。 有没有办法这样做,比如指示.sh文件的绝对路径 (在我们的例子中是 basedirectory+nomdossier+"/"+nomfichier+".sh )?
【问题讨论】: