首页 > 解决方案 > 为什么我的文件追加了一个新行,而我没有指定它?

问题描述

我已经制作了这个脚本,但最后的文件附加部分使 .bat 文件在指定变量 %Ipconfig% 后创建了一个新行。它为什么这样做以及我如何阻止它这样做,以便将其写入 .bat 文件中:

:loop
ping 192.168.0.123 -l 65500 -w 1 -n 1
:goto :loop

而不是这个:

:loop
ping 192.168.0.123
 -l 65500 -w 1 -n 1
:goto :loop
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

FileDelete, %A_Temp%\Temporarybat.bat
FileDelete, %A_Temp%\ip_docu.txt

TempFile=%A_Temp%\ip_temp.txt
Run %comspec% /c "ipconfig > %TempFile%",,Hide
Loop, read, C:\Users\Gebruiker\AppData\Local\Temp\ip_temp.txt, C:\Users\Gebruiker\AppData\Local\Temp\ip_docu.txt
{
    if InStr(A_LoopReadLine, "IPv4")
        FileAppend, %A_LoopReadLine%`n
}
FileRead, Ip4Line, C:\Users\Gebruiker\AppData\Local\Temp\ip_docu.txt
Ipconfig := Substr(Ip4Line, 40)

FileAppend, 
(
:loop
ping %Ipconfig% -l 65500 -w 1 -n 1
:goto :loop
), %A_Temp%\Temporarybat.bat

MsgBox, 1, ..., don't press OK,

ifmsgbox Cancel
exitapp

ifmsgbox OK
loop, 1
{
Run %comspec% /c %A_Temp%\Temporarybat.bat, , max
}

标签: autohotkey

解决方案


我现在已通过使用 StringLen 确定字符串的长度,然后使用该长度复制整个字符串的正确部分来解决此问题。现在脚本可以工作了。


推荐阅读