Run Ghost blog locally with python script
Question:
I have installed ghost blog locally on Windows 10.
To run ghost, I run the following the commands manually on Windows prompt;
$ C:UsersjohnKDropboxjkghost
$ ghost start
I want to automate this with a Python script. This is how my Python script looks.
import os
os.system(r"C:UsersjohnKDropboxjkghost")
os.system("ghost start")
Unfortunately, I get the following error;
'C:UsersjohnKDropboxjkghost' 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.
I am using Python v3.9, Windows 10
Answers:
You need to understand what you are doing in your Windows prompt first to replicate the behavior:
$ C:UsersjohnKDropboxjkghost
means you change the working directory to point to C:UsersjohnKDropboxjkghost
(it’s kinda shortcut for cd C:UsersjohnKDropboxjkghost
) and then:
$ ghost start
executes ghost
executable (.bat
, .exe
whatever it is) located in that directory and passing start
as invocation argument. So in fact your ghost
executable could theoretically be run with one-liner:
$ C:UsersjohnKDropboxjkghostghost start
To mimic that in your python script you can either try to just run above oneliner or first change current working directory for Python and then run your executable. More/less like this:
import os
os.chdir(r"C:UsersjohnKDropboxjkghost")
os.system("ghost start")
I have installed ghost blog locally on Windows 10.
To run ghost, I run the following the commands manually on Windows prompt;
$ C:UsersjohnKDropboxjkghost
$ ghost start
I want to automate this with a Python script. This is how my Python script looks.
import os
os.system(r"C:UsersjohnKDropboxjkghost")
os.system("ghost start")
Unfortunately, I get the following error;
'C:UsersjohnKDropboxjkghost' 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.
I am using Python v3.9, Windows 10
You need to understand what you are doing in your Windows prompt first to replicate the behavior:
$ C:UsersjohnKDropboxjkghost
means you change the working directory to point to C:UsersjohnKDropboxjkghost
(it’s kinda shortcut for cd C:UsersjohnKDropboxjkghost
) and then:
$ ghost start
executes ghost
executable (.bat
, .exe
whatever it is) located in that directory and passing start
as invocation argument. So in fact your ghost
executable could theoretically be run with one-liner:
$ C:UsersjohnKDropboxjkghostghost start
To mimic that in your python script you can either try to just run above oneliner or first change current working directory for Python and then run your executable. More/less like this:
import os
os.chdir(r"C:UsersjohnKDropboxjkghost")
os.system("ghost start")