Jump to content

Troubleshooting opening file after it is saved


Kevib
 Share

Go to solution Solved by Jos,

Recommended Posts

Hello,

 

I'm trying to make a autoit file that generates a .html file and writes some data in there, after that is want it to open the .html file in any kind of browser. The problem I'm having is that shellexecute "uses" the file before it can be saved so it will give me the error can not save the file, file allready in use. Does someone know a way so I can open the file after it is saved?

 

Code: 

FileOpen(@ScriptDir & "Proefwerk.html", 1)

RunWait("notepad.exe C:Usersk3v1nDesktop 2ScriptProefwerkProefwerk.html")

 

WinWaitActive("Proefwerk - Notepad")

 

Send("<body>{ENTER}<title>hallo</title>{ENTER}<h1>Dit is door een geest gemaakt.</h1>{ENTER}<p>Boehoehoe wat eng<p>{ENTER}</body>")

Sleep(500)

 

WinClose("Proefwerk - Notepad")

WinWaitActive("Notepad", "Save")

Send("!s")

Sleep(2000)

 

ShellExecute("C:Usersk3v1nDesktop 2ScriptProefwerkProefwerk.html")

Edited by Melba23
Fixed tags
Link to comment
Share on other sites

  • Developers

Don't use Notepad but write directly to the file .... something like this:

$fh = FileOpen(@ScriptDir & "\Proefwerk.html", 1)
FileWriteLine($fh,"<body>")
FileWriteLine($fh,"<title>hallo</title>")
FileWriteLine($fh,"<h1>Dit is door een geest gemaakt.</h1>")
FileWriteLine($fh,"<p>Boehoehoe wat eng<p>")
FileWriteLine($fh,"</body>")
FileClose($fh)
ShellExecute(@ScriptDir & "\Proefwerk.html")

Jos :)

ps. trouwens interessante tekst in de webpagina.

Edited by Jos

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

I had to write a script for school and the assignment was to make a AutoIt script that opens a editor and writes a Webpage and saves it as a .html and then it needs to open automaticly and my teacher showed it as it was typing by itself like it does in mine. So is it possible to still show it is typing but without the error of course.

ps: de text was gewoon gebrabbel. ;)

Kevin

Link to comment
Share on other sites

  • Developers
  • Solution

Sure, then don't do the FileOpen() as that is only needed when you process records directly.

Success,

Jos

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

Now i have a bit different issue, because without the line FileOpen(@ScriptDir & "Proefwerk.html", 1) it wont make a blank tekst file. Ofcourse opening like: RunWait("notepad.exe C:Usersk3v1nDesktop 2ScriptProefwerkProefwerk.html") will ask you if you want to make a file but i cant seem to get it to work by sending the answer to the question with: Send("!y") like I had to do to save the file.

Kevin

Link to comment
Share on other sites

  • Developers

When you need to create the file you could use the fileOpen() as you did, but that needs to be followed by a FileClose(), more or less in the same way I showed in my first reply.

This is required to release the filelock.

Jos

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

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...