Jump to content
Sign in to follow this  
Kevib

Troubleshooting opening file after it is saved

Recommended Posts

Kevib

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

Share this post


Link to post
Share on other sites
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Kevib

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

Share this post


Link to post
Share on other sites
Kevib

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

Share this post


Link to post
Share on other sites
Jos

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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
Sign in to follow this  

×