我正在尝试使用curl
连接到Splunk API并运行搜索并将结果存储到.csv
文件中。我可以使用subprocess
模块和powershell.exe
进行此操作,如下面的代码块所示
powershell_path = "C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
search_string = '<search to be used>'
curl_command = '\ncurl -k -u <other args>'
subprocess.call([powershell_path, search_string, curl_command])
但是,我希望能够在不使用powershell.exe
的情况下执行此操作。我尝试用powershell.exe
的路径替换路径curl.exe
,然后我收到错误,告诉我我的search_string
和curl_command
变量中有非法字符(使用\
帮助逃避他们,当我尝试直接使用subprocess.call
中的路径时:
subprocess.call(['<path to curl.exe>', '<full search string>, 'curl -k -u <other args>'])
我收到错误WindowsError: [Error 2] The system cannot find the file specified
(我检查了文件路径并尝试os.join
,无处可去)。如何在Python中使用curl连接到Splunk API,运行搜索,将结果保存到csv
,并在不调用Powershell等外部应用程序的情况下完成所有这些操作?