Yusuf Khan
01/14/2022, 5:34 PMrun_in_pwsh = ShellTask(name="Powershell run", shell="pwsh")
this is what I was trying to run. Then within the flow I had: run_in_pwsh(command='ls')
The documentation for the shell argument says 'shell to run the command with; defaults to "bash"'. I assumed it would accept whatever as long as that kicked off in the terminal correctly? What I'm actually trying to do is run an azure command line utility called 'azcopy' (which is not part of the generic az cli). I need to do it both on a windows machine and a linux machine. Having separate scripts is fine. Any thoughts for how I could/should do this on windows?Kevin Kho
Yusuf Khan
01/14/2022, 5:36 PMKevin Kho
Yusuf Khan
01/14/2022, 6:22 PMwinshell = ShellTask(shell=True)
with Flow("ShellAzCopy") as flow:
winshell(command='ls')
flow.run()
and
winshell = ShellTask(shell=r"C:\\Windows\\System32\\bash.exe")
with Flow("ShellAzCopy") as flow:
winshell(command='ls')
flow.run()
Kevin Kho
Kevin Kho
winshell = ShellTask(shell="bash")
Yusuf Khan
01/14/2022, 6:25 PMfilename
.
TypeError: expected str, bytes or os.PathLike object, not boolYusuf Khan
01/14/2022, 6:26 PMYusuf Khan
01/14/2022, 6:27 PMKevin Kho
Kevin Kho
Yusuf Khan
01/14/2022, 6:36 PMYusuf Khan
01/14/2022, 6:37 PMKevin Kho
Zanie
Zanie
shell=True
on the Popen call if the platform is win32 to ensure the PATH is passed through. The tasksās shell
option isnāt the same as that.Zanie
sys.platform
in wsl2?Yusuf Khan
01/14/2022, 6:50 PM>> sys.platform'linux'
Yusuf Khan
01/14/2022, 6:51 PMYusuf Khan
01/14/2022, 6:57 PMwinshell = ShellTask(shell="/mnt/c/Windows/System32/bash.exe")
I get an exit code 1, even though I'm running my .py file from a terminal as adminZanie
Zanie
Yusuf Khan
01/14/2022, 7:03 PMYusuf Khan
01/14/2022, 7:11 PMwinshell = ShellTask(shell="/bin/bash.exe")
this also returns 1Zanie
""
Yusuf Khan
01/14/2022, 7:15 PMwinshell = ShellTask(shell="")
with Flow("ShellAzCopy") as flow:
winshell(command='ls')
flow.run()
Zanie
Zanie
Yusuf Khan
01/14/2022, 8:53 PMwinshell = ShellTask(shell="bash")
with Flow("ShellAzCopy") as flow:
winshell(command='')
flow.run()
Yusuf Khan
01/14/2022, 8:53 PMwinshell = ShellTask(shell="/mnt/c/Windows/System32/bash.exe")
with Flow("ShellAzCopy") as flow:
winshell(command='')
flow.run()
Yusuf Khan
01/14/2022, 9:21 PM@task
def run_subprocess(cmd):
completed = subprocess.run(["pwsh", "-Command", cmd])
return completed
with Flow("ShellAzCopy") as flow:
cmd = Parameter("cmd")
flow.add_task(run_subprocess)
run_subprocess.bind(cmd=cmd, flow=flow)
flow.run_config = LocalRun(
working_dir="C:\\Users\\ykadmin081021\\Documents\\Projects\\ToolsTesting\\prefect_trial\\shell_demo\\"
)
flow.run(cmd = ".\\azcopy_shell.ps1")
Yusuf Khan
01/14/2022, 9:22 PMKevin Kho
Kevin Kho
with Flow("ShellAzCopy") as flow:
cmd = Parameter("cmd")
run_subprocess(cmd=cmd)