我已经在Windows 10上本地安装了鬼博客。
要运行幽灵,我在Windows提示符下手动运行以下命令;
$ C:\Users\johnK\Dropbox\jk\ghost
$ ghost start我想用Python脚本实现自动化。这就是我的Python脚本的样子。
import os
os.system(r"C:\Users\johnK\Dropbox\jk\ghost")
os.system("ghost start")不幸的是,我得到了以下错误;
'C:\Users\johnK\Dropbox\jk\ghost' is not recognized as an
internal or external command, operable program or batch file.
Working directory is not a recognisable Ghost installation.
Run `ghost start` again within a folder where Ghost was installed
with Ghost-CLI.我正在使用Pythonv3.9,Windows 10
发布于 2022-09-17 11:34:56
首先,您需要了解在Windows提示符中要做什么才能复制行为:
$ C:\Users\johnK\Dropbox\jk\ghost意味着您将工作目录更改为指向C:\Users\johnK\Dropbox\jk\ghost (这是cd C:\Users\johnK\Dropbox\jk\ghost的某种快捷方式),然后:
$ ghost start执行位于该目录中的ghost可执行文件(.bat,.exe ),并将start作为调用参数传递。因此,实际上您的ghost可执行文件理论上可以使用一行程序运行:
$ C:\Users\johnK\Dropbox\jk\ghost\ghost start要在python脚本中模拟这种情况,可以尝试在oneliner上面运行,或者首先更改Python的当前工作目录,然后运行可执行文件:
import os
os.chdir(r"C:\Users\johnK\Dropbox\jk\ghost")
os.system("ghost start")https://stackoverflow.com/questions/73724654
复制相似问题