我需要通过Google Cloud功能中的python中的Subprocess获得一些执行的过程。
import subprocess
import os
def hello_world(request):
print(subprocess.call(["echo", "hello","world"]))
预期输出:你好,世界
实际输出:0
Google函数会阻止子流程的执行还是我需要以其他方式接收输出
请记住,Cloud Functions是无服务器的计算平台,主要功能之一是没有要配置,管理,修补或更新的服务器。
应该使用python中的子进程来访问系统命令,因此,基本上,您试图从运行Cloud Function的计算机获得响应,而这是不可能的。
在您的特定情况下,使用以下代码将获得预期的输出:
def hello_world(request):
return f'Hello, world!'