在Linux上使用python更新txt文件内容

时间:2016-12-29 12:15:32

标签: python linux python-2.7 subprocess

 if len(ip) > 0: 

        #All tabs
        filename ="output"+str(ip)+".txt"
        action = 'FullExport'
        menu_action = 'all'
        arg_list = '/home/venv/upnp/bin/python2.7 /home/code/upnp/Client/UPNP_Client_Cmd_Line.py'             
        arg_list += ' --action='
        arg_list += action
        arg_list += ' --ip='
        arg_list += (str(ip))
        arg_list += ' --menu='
        arg_list += menu_action
        arg_list += ' > ' + filename
        arg_list += ' 2>/dev/null'

        time.sleep(3)

        #Deleted tabs

        filename ="output"+str(ip)+".txt"
        action = 'FullExport'
        menu_action = 'deleted'
        arg_list = '/home/venv/upnp/bin/python2.7 /home/code/upnp/Client/UPNP_Client_Cmd_Line.py'             
        arg_list += ' --action='
        arg_list += action
        arg_list += ' --ip='
        arg_list += (str(ip))
        arg_list += ' --menu='
        arg_list += menu_action
        arg_list += ' >>' + filename
        arg_list += ' 2>/dev/null'


        x = subprocess.Popen(arg_list, shell=True, executable='/bin/bash')

        #Wait for all files to be fully exported 

我正在尝试更新linux上的txt文件。当我向机器发送第二个命令时,它会删除以前的文件内容。

我想在同一文件中的所有标签之后导出#deleted标签的内容。 arg_list + =' >>' + filename此命令不起作用。任何帮助,将不胜感激。

0 个答案:

没有答案
相关问题