a-shell
a-shell copied to clipboard
Crash using python, subprocess and pickfolder
I have this python script:
import subprocess
import rich
from rich.console import Console
from rich.markdown import Markdown
from rich import print
import os
from time import sleep
def ashell_environment(console):
"""
Relly on pickFolder in ashell to create the environment
:param console: rich console
:return vault_path, blog_path
"""
vault = ""
blog = ""
console.print("Please provide your [u bold]obsidian vault[/] path: ")
cmd = "pickFolder"
sleep(5) # The user needs to read the message !
subprocess.Popen(cmd, stdout=subprocess.PIPE)
# Now, the os.getcwd() change for the pickedFolder
vault = os.getcwd()
subprocess.Popen(cmd, stdout=subprocess.PIPE)
console.print("Please provide the [u bold]blog[/] repository path: ")
sleep(5) # The user needs to read the message !
subprocess.Popen(cmd, stdout=subprocess.PIPE)
blog = os.getcwd()
# return to default environment
cmd = "cd"
subprocess.Popen(cmd, stdout=subprocess.PIPE)
return vault, blog
console = Console()
vault, blog=ashell_environment(console)
print(vault, blog)
The script crash at the moment where pickFolder open.
I fixed the app crash with adding a "Press any key to continue" (waiting for any input) I dunno if it's possible to add something around this (aka waiting to close pickFolder before continue a python script).