autohotkey - 为什么我的文件追加了一个新行,而我没有指定它?
问题描述
我已经制作了这个脚本,但最后的文件附加部分使 .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
}
解决方案
我现在已通过使用 StringLen 确定字符串的长度,然后使用该长度复制整个字符串的正确部分来解决此问题。现在脚本可以工作了。
推荐阅读
- composer-php - 无法更新:“无法获取可用的更新数据。”
- oracle - 在 Oracle 中更新 6200 万条记录
- react-native - React Native:平面列表和 react-native-menu
- node.js - 离子代理设置不正常,下载和提取需要很长时间
- ios - Swift - 为什么我选择时无法更改色调?
- java - 为什么不能从 Selenium 的链接中获取所有数据
- artillery - How can I escape "." characters in Artillery to prevent nesting?
- python - Is there a way to locate a data frame between a set of date ranges?
- java - 在同步块中使用 Object.class 锁有什么影响?
- python - python我的日期转换函数在将datetime.date格式转换为“yyyy-mm-dd”时抛出错误