回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有下面的脚本,我不能让它搜索字符串然后输出值</p>
<p>如何获取参数并将其拆分,以便搜索“endpoint machine name=”,然后输出其值</p>
<p>命令如下:</p>
<pre><code>python -u HostnameScript.py "discover-repository-location=null, Employee Notified=null, Manager Title=Exec Dir Biostatistics, date-detected=Mon Aug 25 16:03:35 PDT 2014, endpoint-machine-name=Davidpc, incident-id=603, sender-ip=null, Machine Name=null, Assigned To=null, Business Unit=Development US"
</code></pre>
<p>我试过将其拆分,但无法正确搜索</p>
<pre><code>import sys, socket, string, commands, os, re, subprocess
arguments=sys.argv[1:]
for args in [item.split(", ") for item in arguments[]:
if item.find("endpoint-machine-name=") != -1
value=item.strip("endpoint-machine-name=")
sys.stdout.write('Hostname=');print value
</code></pre>
<p>我最后得到的只是</p>
<pre><code>Hostname=discover-repository-location=null, Employee Notified=null, Manager Title=Exec Dir Biostatistics, date-detected=Mon Aug 25 16:03:35 PDT 2014, endpoint-machine-name=Davidpc, incident-id=603, sender-ip=null, Machine Name=null, Assigned To=null, Business Unit=Development US
</code></pre>