如何通过AutoHotKey将参数传递给内置的Windows命令?

时间:2015-08-23 23:28:44

标签: windows file cmd autohotkey

我尝试创建一个简单的文件合并工具,将拆分日志文件合并到一个文本文件中。

FileSelectFolder, folder, \\Myserver\Data\
InputBox, filename, Save File,Please type the name you will call the merged file.`n The file will be saved in the folder "merged" of the same root directory as its "part files" are located., , , , , , , ,merged_file.txt
if errorlevel = 1
exitApp
IfExist, %folder%\merged\%filename%
MsgBox, 4, File Overwrite -or- Append?, The file already exists.  Do you want to append to this file?  `nNote:  If you select "No" the existing file will be replaced during this process.
ifmsgbox, no
FileDelete %folder%\merged\%filename%
FileCreateDir, %folder%\merged
IfExist %folder%\merged\%filename%_file_list.txt
FileDelete %folder%\merged\%filename%_file_list.txt
Runwait, %COMSPEC% /c copy /k %folder%\*.log %folder%\merged\%filename% 
ExitApp

我不想使用AHK fileread fileappend ,因为日志文件非常大~40mb。

上述代码不会产生任何错误,但也不会生成任何文件。 我尝试添加"参数没有成功。

1 个答案:

答案 0 :(得分:0)

好的还有一枪!

事实证明,您需要在命令字符串中引用Path以与COMSPEC一起使用。

我之前也正确地说过,Copy命令没有/ K开关或选项。有Compsec开关/ K,它保持终端打开,a / c表示关闭终端。

复制也是你的语法错误。为了使文件与Copy连接,您需要执行以下操作:

Copy mergedfile.txt+file2merge.txt newmergedfile.txt

但我建议您使用Type来连接文本文件:

RunWait, %COMSPEC% /c type "%folder%\*.log" >> "%folder%\merged\%filename%"