Write text to a file: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Added category links.)
m (Fix a typo)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{|align=right
{{PageAuthor|rainmanp7}}
|<small>Author: [[{{ns:2}}:rainmanp7|rainmanp7]] ([[{{ns:3}}:rainmanp7|talk]], [[{{ns:-1}}:Contributions/rainmanp7|contrib]])</small>
 
|}
<br style="clear:both;">
== Description ==
== Description ==
This example shows you how to write text to a new file.
This example shows you how to write text to a new file.
For more advanced examples, see [[Reading and Writing in files]].


== The Script ==
== The Script ==
<highlight-nsis>
<highlight-nsis>
FileOpen $9 apachesrvin.bat w ;Opens a Empty File an fills it
FileOpen $9 apachesrvin.bat w ;Opens a Empty File and fills it
FileWrite $9 "cd $INSTDIR\apache$\r$\n"
FileWrite $9 "cd $INSTDIR\apache$\r$\n"
FileWrite $9 "apache -n Apache -k install$\r$\n"
FileWrite $9 "apache -n Apache -k install$\r$\n"
FileWrite $9 "net start Apache$\r$\n"
FileWrite $9 "net start Apache$\r$\n"
FileWrite $9 "exit$\r$\n"
FileWrite $9 "exit$\r$\n"
FileClose $9 ;Closes the empty file
FileClose $9 ;Closes the filled file
</highlight-nsis>
</highlight-nsis>


[[{{ns:14}}:Code Examples]]
[[Category:Code Examples]]

Latest revision as of 10:23, 15 April 2020

Author: rainmanp7 (talk, contrib)


Description

This example shows you how to write text to a new file.

For more advanced examples, see Reading and Writing in files.

The Script

FileOpen $9 apachesrvin.bat w ;Opens a Empty File and fills it
FileWrite $9 "cd $INSTDIR\apache$\r$\n"
FileWrite $9 "apache -n Apache -k install$\r$\n"
FileWrite $9 "net start Apache$\r$\n"
FileWrite $9 "exit$\r$\n"
FileClose $9 ;Closes the filled file