私はPythonに比較的慣れていません。ですから、私の素朴さを許してください。文字列をファイルに書き込もうとすると、変数の後の文字列の部分が新しい行に置かれますが、そうすべきではありません。私はpython 2.6.5 btwを使用しています
arch = subprocess.Popen("info " + agent + " | grep '\[arch\]' | awk '{print $3}'", shell=True, stdout=subprocess.PIPE)
arch, err = arch.communicate()
strarch = str(arch)
with open ("agentInfo", "a") as info:
info.write("Arch Bits: " + strarch + " bit")
info.close()
os.system("cat agentInfo")
望ましい出力:
"Arch Bits: 64 bit"
実際の出力:
"Arch Bits: 64
bits"