I'm looking for the simplest and/or best way to run two do-loops concurrently. I can do this with two separate scripts running in two separate windows...but I'm sure there's a more efficient way. I played a little with the "workspace" method, but haven't yet figured it all out. Is the workspace approach the best way? Is it the easiest way? A sample script that launches two do-until loops concurrently would be appreciated. Here are to two scripts I have running in separate windows now:
SCRIPT 1--
$relayoff = {
do {
$request = get-content relay.txt
} until ($request -notmatch '0')
&$relayon
}
$relayon = {
$port= new-object system.io.ports.serialport com7,4800,none,8,one
$port.open()
echo 1 > relay.txt
do {
$hold = get-content relay.txt
$port.writeline("1InthebeginningwastheWord,andtheWordwaswithGod,andtheWordwasGod.2HewasinthebeginningwithGod.3AllthingsweremadethroughHim,andwithoutHimnothingwasmadethatwasmade.4InHimwaslife,andthelifewasthelightofmen.5Andthelightshinesinthedarkness,andthedarknessdidnotcomprehend[a]it.
")
} until ($hold -match '0')
$port.close()
&$relayoff
}
&$relayoff
SCRIPT 2--
$wait = {
do {
$read = get-content relay.txt
$request = $read
} until ($read -notmatch '0')
do {
$read = get-content relay.txt
} until ($read -match '1')
&$play
}
$play = {
.\sounder.exe $request
Wait-Process sounder
echo 0 > relay.txt
&$wait
}
$read = get-content relay.txt
&$wait
Flags and other information are passed between these two scripts and a GUI via the text file "relay.txt". So currently there are three programs running concurrently: two powershell windows and the GUI. If I can combine the two scripts, I will eliminate one of these windows. I'll still need the text file for the sake of the GUI, but not for the do-loop variables.
- Edited by Chalk-X CPG Monday, February 09, 2015 7:13 PM