hymkor / expect

Expect-lua for Windows
MIT License
118 stars 15 forks source link

error message [syntax error] using example in Windows 10 #23

Closed wolf-li closed 2 years ago

wolf-li commented 2 years ago

Hi, guys: I get a error message when I run the example. Could anyone know that?

sample.lua

echo(true)
if spawn([[C:\Program Files\Git\usr\bin\ssh.exe]],"xxx@1xxxxx3") 
then
  expect("password:")
  echo(false)
  send("xxxxx\r")
  expect("~]$")
  echo(true)
  send("exit\r")
end

terrmial shows error message: sample.lua at EOF: syntax error

hymkor commented 2 years ago

@wolf-li

Thank you for reporting.

Would you append CRLF at the last line of sample.lua ?

On my environment, when I remove CRLF from the last line of the script, I see the error message you reported.

wolf-li commented 2 years ago

@hymkor

Thank you very much for your reply. I tried the method you said, but it didn't work. As shown in the figure below .
Using expect-v0.6.0-amd64.zip and v0.5, It's the same problem.

export

hymkor commented 2 years ago

@wolf-li :

When you edit the script by Visual Studio Code, it is possible that the last line does not have CRLF.

To resolve this problem , two methods exist.

  1. Append the empty line after end .
  2. Try the new version: Release v0.6.1 · hymkor/expect.
    where I fixed the bug that When a script did not end with CRLF, the last line was ignored.

Would you try one of these methods ?

wolf-li commented 2 years ago

@wolf-li :

When you edit the script by Visual Studio Code, it is possible that the last line does not have CRLF.

To resolve this problem , two methods exist.

  1. Append the empty line after end .
  2. Try the new version: Release v0.6.1 · hymkor/expect. where I fixed the bug that When a script did not end with CRLF, the last line was ignored.

Would you try one of these methods ?

Good job, All of these solutions can solve the problem. But I recommend using the second method. If the script is written incorrectly, the session will not get stuck as shown in the figure below.

export2

Many thanks to the author for his work.

hymkor commented 2 years ago

I'm glad the problem is solved .

Can I close this issue ?

wolf-li commented 2 years ago

Yes. Thanks for your work.