a-shell icon indicating copy to clipboard operation
a-shell copied to clipboard

Crash using python, subprocess and pickfolder

Open Mara-Li opened this issue 2 years ago • 1 comments

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.

Mara-Li avatar Feb 25 '22 16:02 Mara-Li

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).

Mara-Li avatar Mar 01 '22 10:03 Mara-Li