AutoHotkey编译的脚本不起作用

时间:2016-05-17 05:35:47

标签: windows command-line lua autohotkey

我编写了一个运行良好的AutoHotkey脚本,但无论我用哪个基本文件(.bin)来编译Ahk2Exe中的exe,它都会因某些未知原因而失败。这是AHK脚本:

in_file = open('filename.csv', 'r')
dict = {}

#should print all rows where field [0] == 1

print('List of rows where column one is equal to zero in alphabetical order of column 2')

for line in in_file:
    line = line.strip('\n')
    fields = line.split(',')

    c1 = fields[0]
    c2 = fields[1]
    c3 = fields[2]
    c4 = fields[3]
    c5 = fields[4]
    c6 = fields[5]
    c7 = fields[6]
    c8 = fields[7]
    c9 = fields[8]
    c10 = fields[9]
    c11 = fields[10]

    if c2 not in dict:
        dict[c2] = c1
    if c3 not in dict:
        dict[c3] = c1
    if c4 not in dict:
        dict[c4] = c1
    if c5 not in dict:
        dict[c5] = c1
    if c6 not in dict:
        dict[c6] = c1
    if c7 not in dict:
        dict[c7] = c1
    if c8 not in dict:
        dict[c8] = c1
    if c9 not in dict:
        dict[c9] = c1
    if c10 not in dict:
        dict[c10] = c1
    if c11 not in dict:
        dict[c11] = c1

name = dict.keys()
sorted_names = sorted(name)
for name in sorted_names:
    c1 = dict[name]
    rows = [row for row in in_file if row ['c1']!= 1]

for row in rows:
    print(c3, c2, c4, c5)

in_file.close() 

以下是我运行它的方式,来自Lua脚本(双引号用于实际路径中的空格):

SetTitleMatchMode, 2
WinGet, PID, PID, Anime Studio ahk_class LM_Wnd
Process, Close, %PID%
if 1 && (%ErrorLevel% != 0)
{
Run, %1%
}

我将变量“path”从Lua传递给AHK脚本(%1%)。我已经尝试将AHK编译的exe设置为以管理员身份运行,但这没有帮助。

--to uncompiled AHK (working code)
os.execute("C:/Users/JWesley/Desktop/AutoHotkey/AutoHotkeyU64.exe ".."\"".."C:/Users/JWesley/Files/AS/Anime Studio Pro/scripts/utility/ReopenAS.ahk".."\"".." "..path)
--to compiled AHK (not working)
os.execute("\"".."C:/Users/JWesley/Files/AS/Anime Studio Pro/scripts/utility/ReopenAS64.exe".."\"".." "..path)

我尝试过使用os.execute('pause')以便我有机会阅读任何命令提示符消息,但第一个消息仍然在暂停的消息打开之前关闭。 编辑:好的,我得到了这个提示打开提示:

path = "C:/Users/JWesley/Desktop/test.anime"

并在提示中收到此消息:

os.execute("cmd.exe /k"..'"C:\\Users\\JWesley\\Desktop\\AutoHotkey\\AutoHotkeyU64.exe" "C:\\Users\\JWesley\\Files\\AS\\Anime Studio Pro\\scripts\\utility\\ReopenAS.ahk" "' .. path .. '"')

1 个答案:

答案 0 :(得分:0)

我在这里找到了一个解决方案:os.execute with filename and argument containing spaces原来它比AutoHotkey更像Lua问题,虽然我仍然不确定为什么编译和未编译的AHK脚本之间存在差异。在Lua中,我检查了路径是否有空格,如果是这样的话:

path = "\""..path.."\""

然后我做了:

com = "\"".."type NUL && ".."\"".."C:/Users/JWesley/Files/AS/Anime Studio Pro/scripts/utility/ReopenAS64.exe".."\"".." "..path.."\""
os.execute(com)

据说这可以防止命令行删除外部引号,这对于路径中的空格是必需的。

现在我唯一的问题是编译脚本由于我的反病毒而运行缓慢,但这是一个单独的问题。

感谢您的反馈。