Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Writing variables to memory versus tmp files

Reply
 
Old 12-08-2006   #1 (permalink)
Marco Shaw


 
 

Writing variables to memory versus tmp files

Instead of having a Powershell window open all the time, I might have PSH
scripts that run at various intervals. I may want the current script to get
variables defined in a previous run.

One way would be to have the script write to a tmp file, and have the next
run pull in any relevant data from that file to use.

I hate having to write temp files...

Perhaps PSH can write a host-based variable, and have that available for the
next run. Even something stored to RAM somehow would be kind of OK
(realizing that I'd lose that on a reboot).

Comments?

Marco



My System SpecsSystem Spec
Old 12-08-2006   #2 (permalink)
Rob Campbell


 
 

RE: Writing variables to memory versus tmp files

Have it both ways, and write temp files to a ram drive?

"Marco Shaw" wrote:

> Instead of having a Powershell window open all the time, I might have PSH
> scripts that run at various intervals. I may want the current script to get
> variables defined in a previous run.
>
> One way would be to have the script write to a tmp file, and have the next
> run pull in any relevant data from that file to use.
>
> I hate having to write temp files...
>
> Perhaps PSH can write a host-based variable, and have that available for the
> next run. Even something stored to RAM somehow would be kind of OK
> (realizing that I'd lose that on a reboot).
>
> Comments?
>
> Marco
>
>
>

My System SpecsSystem Spec
Old 12-08-2006   #3 (permalink)
David L. Bork


 
 

RE: Writing variables to memory versus tmp files

Marco,

I would suggest saving the variables to the registry if you need to save
state. You can access the registry the same way you access a file on a hard
drive. See the Getting started manual that ships with the Powershell
documentation for examples.

-Daivd

"Marco Shaw" wrote:

> Instead of having a Powershell window open all the time, I might have PSH
> scripts that run at various intervals. I may want the current script to get
> variables defined in a previous run.
>
> One way would be to have the script write to a tmp file, and have the next
> run pull in any relevant data from that file to use.
>
> I hate having to write temp files...
>
> Perhaps PSH can write a host-based variable, and have that available for the
> next run. Even something stored to RAM somehow would be kind of OK
> (realizing that I'd lose that on a reboot).
>
> Comments?
>
> Marco
>
>
>

My System SpecsSystem Spec
Old 12-08-2006   #4 (permalink)
Marco Shaw


 
 

Re: Writing variables to memory versus tmp files

> Have it both ways, and write temp files to a ram drive?

A "ram drive"?


My System SpecsSystem Spec
Old 12-08-2006   #5 (permalink)
Marco Shaw


 
 

Re: Writing variables to memory versus tmp files

> I would suggest saving the variables to the registry if you need to save
> state. You can access the registry the same way you access a file on a
> hard
> drive. See the Getting started manual that ships with the Powershell
> documentation for examples.


Interesting idea... My data could be quite large though...

Marco


My System SpecsSystem Spec
Old 12-08-2006   #6 (permalink)
Rob Campbell


 
 

Re: Writing variables to memory versus tmp files

Basically an emulated logical disk. It only exists in memory, but the looks
like a physical disk to the OS. I believe ramdisk.sys is the device drive
you use to create one.

"Marco Shaw" wrote:

> > Have it both ways, and write temp files to a ram drive?

>
> A "ram drive"?
>
>
>

My System SpecsSystem Spec
Old 12-08-2006   #7 (permalink)
RichS


 
 

Re: Writing variables to memory versus tmp files

If its large then tmp file would probably be best. Does your process need to
be restartable at current position after a reboot? If so the persisting the
data to disk in some format would be safest
--
Richard Siddaway

Please note that all scripts are supplied "as is" and with no warranty


"Marco Shaw" wrote:

> > I would suggest saving the variables to the registry if you need to save
> > state. You can access the registry the same way you access a file on a
> > hard
> > drive. See the Getting started manual that ships with the Powershell
> > documentation for examples.

>
> Interesting idea... My data could be quite large though...
>
> Marco
>
>
>

My System SpecsSystem Spec
Old 12-08-2006   #8 (permalink)
Lee Holmes [MSFT]


 
 

Re: Writing variables to memory versus tmp files

I think a temporary file is ultimately the correct backing store for
temporary data like this. When you create them properly (i.e.:
[System.IO.Path]::GetTempFileName()), Windows has lots of mechanisms to help
keep your system clean.

It sounds like you hate /managing/ temp files. Why not write a few functions
that abstract that from you? It sounds like you'd want:

Set-PersistentVariable foo $fooData
$fooData = Get-PersistentVariable foo

You could have your prompt function check for and clean up old unused
variables every 10th prompt or something.

For simple data types, the Import-CliXml and Export-CliXml cmdlets should be
all that you need for persistence. If you think you'll be dealing with
really complex data, then you've got a bit more work cut out for you.
Serializing objects to disk is a bit tricky, since you need to intimately
know the details of what is important to persist.

--
Lee Holmes [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


"Marco Shaw" <marco@Znbnet.nb.ca> wrote in message
news:eIt1bktGHHA.816@TK2MSFTNGP06.phx.gbl...
>> I would suggest saving the variables to the registry if you need to save
>> state. You can access the registry the same way you access a file on a
>> hard
>> drive. See the Getting started manual that ships with the Powershell
>> documentation for examples.

>
> Interesting idea... My data could be quite large though...
>
> Marco
>



My System SpecsSystem Spec
Old 12-08-2006   #9 (permalink)
Jacques Barathon [MS]


 
 

Re: Writing variables to memory versus tmp files

"Lee Holmes [MSFT]" <lee.holmes@online.microsoft.com> wrote in message
news:%23AK2UnuGHHA.3540@TK2MSFTNGP02.phx.gbl...
>I think a temporary file is ultimately the correct backing store for
>temporary data like this. When you create them properly (i.e.:
>[System.IO.Path]::GetTempFileName()), Windows has lots of mechanisms to
>help keep your system clean.


One limitation with the GetTempFileName() option though is that you still
need to keep the temp file name somewhere for your next sessions.

Depending on your actual requirement, you may want to save your temp file
names in one single location, either in a text file or in the registry -
having them in the registry might help clean them up individually, whereas
storing them in a file would allow for (relatively) easy transfer to another
computer along with the temp files themselves if cross-system sharing is
required in addition to post-reboot persistence.

Jacques

My System SpecsSystem Spec
Old 12-08-2006   #10 (permalink)
Adam Milazzo


 
 

Re: Writing variables to memory versus tmp files

Marco Shaw wrote:
> Instead of having a Powershell window open all the time, I might have PSH
> scripts that run at various intervals. I may want the current script to get
> variables defined in a previous run.
>
> One way would be to have the script write to a tmp file, and have the next
> run pull in any relevant data from that file to use.
>
> I hate having to write temp files...


Instead of saving them to "temp files", save them to non-temp files. I
mean, a file in a well-known location that's used for tracking this
information.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Defragment versus moving files? Virtual Server
Display variables in memory PowerShell
video files, vista versus XP Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46