怎么做发送(“发送(”$ readme 1“)”)?

问题描述 投票:-1回答:3

如何正确执行此命令发送(“发送(”$ readme 1“)”)?

Send("Send("$readme 1")")

所以当脚本运行时会输入:

发送(“无论是关于$ readme 1”)

autoit
3个回答
0
投票

根据the AutoIt manual,您可以用单引号和双引号括起字符串。这意味着

Send('Send("$readme 1")')

应该做你想做的事。

另一种选择是使用双引号在双引号字符串中标记文字双引号(p!):

Send("Send(""$readme 1"")")

0
投票

如前所述,在AutoIt中,变量不能包含空格(如果尝试,应该会出现编译错误) 另外(如前所述),您只需写入文件而不是模拟“使用编辑器”。

可悲的是,你的问题不是很清楚,但下列之一应该符合你的需求:

要将send("Hello")这样的行写入文件,请使用:

$readme1 = "Hello"
FileWriteLine("C:\tmp\test.txt", 'send("' & $readme1 & '")')

如果你想字面写send("$readme1")

FileWriteLine("C:\tmp\test.txt", 'send("$readme1")')

两种情况下的关键是正确使用引号(AutoIt使用两种引号:"'


0
投票

Send('Send("$readme 1")', 1)输出Send( "$readme 1" )。请注意, 1的原始密钥(使用特殊字符或保留关键字)。

写入文件的示例:

; variant one: create new file and write into
Global $sYourFile    = @DesktopDir & '\myNewFile.txt'
Global $sFileContent = 'Line 1' & @CRLF & 'Line 2' & @CRLF

Func _writeFile($sFile, $sText)
    Local $hFile = FileOpen($sFile, 2 + 8 + 256)
    FileWrite($hFile, $sText)
    FileClose($hFile)
EndFunc

_writeFile($sYourFile, $sFileContent)

MsgBox(64, 'Information', 'Variant one was executed. Please check your new file on the Desktop.'

; variant two: create new file and append text line by line
Global $sYourFile = @DesktopDir & '\myNewFile.txt'

Func _appendLineToFile($sFile, $sLineText)
    Local $hFile = FileOpen($sFile, 1 + 8 + 256)
    FileWriteLine($hFile, $sLineText)
    FileClose($hFile)
EndFunc

_appendLineToFile($sYourFile, 'Line 3')
_appendLineToFile($sYourFile, 'Line 4')
_appendLineToFile($sYourFile, 'Line 5')
_appendLineToFile($sYourFile, 'Line 6')

MsgBox(64, 'Information', 'Variant two was executed. Please check your new file on the Desktop.')

; variant three: replace text in file on specific line
#include-once
#include <File.au3>

Global $sYourFile = @DesktopDir & '\myNewFile.txt'

_FileWriteToLine($sYourFile, 2, 'New line 2', True)
_FileWriteToLine($sYourFile, 4, 'New line 4', True)

MsgBox(64, 'Information', 'Variant three was executed. Please check your new file on the Desktop.')
© www.soinside.com 2019 - 2024. All rights reserved.