Hello, I am trying to run a version of the bestpra...
# ask-community
m
Hello, I am trying to run a version of the bestpractices.py example from the documents on a windows server. Can anyone tell me why the shellcommand task never returns?
k
Hello @mark.smith, could you please move the code to a thread so that it doesn’t crowd the main channel? I think the issue here is that you are on Windows and the ShellTask has issues as cmd does not seem to support running a script. You need to install bash and have it in the path.
m
Done....
#--------------------------------------------------------------
# Imports
#--------------------------------------------------------------
# basic imports
from prefect import Flow, Parameter, task
# specific task class imports
from prefect.tasks.shell import ShellTask
#--------------------------------------------------------------
# Define custom task functions
#--------------------------------------------------------------
@task
def plus_one(x):
    
"""A task that adds 1 to a number"""
    
return x + 1
@task
def build_command(name):
    
return 'echo "HELLO, {}!"'.format(name)
@task
def print_it(x):
    
print(x)
#--------------------------------------------------------------
# Instantiate task classes
#--------------------------------------------------------------
run_in_cmd = ShellTask(name='run a command', shell='cmd', return_all=True)
#--------------------------------------------------------------
# Open a Flow context and use the functional API (if possible)
#--------------------------------------------------------------
with Flow('Best Practices') as flow:
    
# store the result of each task call, even if you don't use the result again
    
two = plus_one(1)
    
# for clarity, call each task on its own line
    
name = Parameter('name')
    
cmd = build_command(name=name)
    
shell_result = run_in_cmd(command=cmd)
    
print_it(shell_result)
    
# use the imperative API where appropriate
    
#shell_result.set_upstream(two)
flow.run(parameters=dict(name='mark'))
k
Thank you! Appreciate it