Jump to content

Problems with Reading and Rewriting


Recommended Posts

I have a feeling this question's been asked before, and I apologize if it has, but I can't seem to find an answer in the manual or these forums.

When I try to Send a block of text that I copied from notepad, it doubles the amount of return characters in the original block of text. For instance, if I use the following (simplified) code:

ShellExecute ("tester.txt")
winwaitactive("tester - Notepad")
$text = WinGetText("tester - Notepad", "")
Send("^a{BS}")
Send($text,1)

With tester holding the following text:

This is the beginning.
This is the middle.
This is the end.

I get the following output:

This is the beginning.

This is the middle.

This is the end.

If I save that and run again, I get this:

This is the beginning.



This is the middle.



This is the end.

I've noticed that I can mostly fix the problem by using StringStripWS($text,4), but it seems kinda hacky and I'm worried that'll cause issues further down the line. Is there something I'm doing wrong here?

Link to comment
Share on other sites

...if I use the following (simplified) code:...

Welcome to the forum.

ShellExecute("tester.txt")
WinWaitActive("tester.txt - Notepad")
$text = WinGetText("tester.txt - Notepad", "")
;$text = ControlGetText("tester.txt - Notepad", "", "Edit1")
MsgBox(0, "", $text)
WinWaitActive("tester.txt - Notepad")
Send("^a{BS}")
Send($text, 1)
Send($text, 0)
Sleep(5000)
ControlSetText("tester.txt - Notepad", "", "Edit1", $text)
The problem seems to be in the send function.

I'll let others comment on it before suggesting that you report this in the bug forum.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Not wanting to risk an edit of the code above, here is a slightly different version of the test...

$line1 = "This is the beginning." & @CRLF
$line2 = "This is the middle." & @CRLF
$line3 = "This is the end."
$all = $line1 & $line2 & $line3
$fh = FileOpen("tester.txt",2)
FileWrite($fh, $all)
FileClose($fh)

ShellExecute("tester.txt")
WinWaitActive("tester.txt - Notepad")
$text = WinGetText("tester.txt - Notepad", "")
;$text = ControlGetText("tester.txt - Notepad", "", "Edit1")
MsgBox(0, "", $text)
WinWaitActive("tester.txt - Notepad")
Send("^a{BS}")
Send($text, 1)
Send($text, 0)
Sleep(1000)
ControlSetText("tester.txt - Notepad", "", "Edit1", $text)
Send() still seems to be the culprit here.

It is as if it is sending one CRLF for CR and one CRLF for LF.

Or am I just being the MSP again?

Comments?

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • Developers

Just thinking out loud:

We are sending "keyboard characters" with send and @crlf really would need to be an {enter} since thats that is the "key" we want to simulate.

I think that both LF as CR independently emulate an {ENTER} and makes you end up with 2 newlines.

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks - that makes sense.

I've used AutoIt to get data from one app and send it to another. I've always trimmed unwanted things like CRLF before sending it to the second app, so I guess that I've never seen this.

Thanks again - maybe the OP can make use of ControlGetText and ControlSetText instead of Send - or trim the info to be sent.

Definitely MSP today.

Edit :-) I'm glad that one of us was thinking :-)

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Under StringSplit in the help file:

Caution if you use the macro @CRLF you are referring to a 2 character string so you will generate extra blanks lines.

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

Thanks a lot for the replies. ControlSetText works perfectly.

Why are you executing the text file instead of using _FileReadToArray?

Mostly because I didn't know it existed. I just picked up AutoIT a few days ago, so I'm still learning the syntax.

I'll try using _FileWriteFromArray in conjunction with that, which I imagine would be a cleaner execution.

Thank you for pointing that out.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...