Author |
|
jeffw_00 Super User
Joined: June 30 2007
Online Status: Offline Posts: 929
|
Posted: February 21 2017 at 19:05 | IP Logged
|
|
|
Hi - Every 15 minutes, I use LaunchApp to run a Perl script that captures the Temperature from a website and writes it to a file. But that means that every 15 minutes a DOS box opens (very briefly) on my WIN7 machine.
Is there any way to have LaunchApp run the DOS box minimized?
Thanks!
/j
(Searching the manuals and help for LaunchApp was not fruitful)
|
Back to Top |
|
|
gg102 Senior Member
Joined: January 29 2013 Location: United States
Online Status: Offline Posts: 245
|
Posted: February 21 2017 at 20:42 | IP Logged
|
|
|
Here's how I ping my smartphone. It's nice. There is NO popup DOS box. I use ph_runscript rather than LaunchApp. The implementation is a little complex.
This takes three steps:
in PH do this:
Formula ph_runscript_0 ( 100, "c:\SomeDirectory\ping_ppc.vbs", "" )
-----------------------------------------------
your ping_ppc.vbs located in "SomeDirectory" is:
' msgbox("DEBUG MSG: About to run the ping .BAT program in the background")
'
Set WshShell = CreateObject("WScript.Shell")
'
'REM Now, run the .bat hidden....
WshShell.Run "c:\SomeDirectory\ping_ppc.bat", 0
----------------------------------------------------
Now, the final thing is to have your .bat located in "SomeDirectory":
@ECHO OFF
cd\
cd SomeDirectory
rem del pingt.txt
ping >c:\SomeDirectory\ping.txt 192.168.x.xxx -w 5000 -n 3
copy /y c:\SomeDirectory\ping.txt c:\SomeDirectory\pingt.txt
------------------------------------
The results are in c:\SomeDirectory\pingt.txt. You can then read that file.
Then I use the FILE MONITOR plugin to trigger PH when the file (pingt.txt) changes.
You can change this to do your functions as needed.
This is just an example and how I do it.
If you need more, let me know.
Your mileage may vary....
Good luck.
Edited by gg102 - February 21 2017 at 20:43
|
Back to Top |
|
|
jeffw_00 Super User
Joined: June 30 2007
Online Status: Offline Posts: 929
|
Posted: February 21 2017 at 21:05 | IP Logged
|
|
|
thanks! Clever solution - was hoping there was a simpler way though :-)
|
Back to Top |
|
|
gg102 Senior Member
Joined: January 29 2013 Location: United States
Online Status: Offline Posts: 245
|
Posted: February 21 2017 at 21:29 | IP Logged
|
|
|
Remember, you only need steps 1 and 2. Just substitute your .BAT and you're running.....
|
Back to Top |
|
|
jeffw_00 Super User
Joined: June 30 2007
Online Status: Offline Posts: 929
|
Posted: February 24 2017 at 18:49 | IP Logged
|
|
|
Tried it - doesn't work for some reason - here's my PH formula:
ph_runscript_0 ( 100, "c:\jeff\insteon\temp.vbs", "" )
here's c:\jeff\insteon\temp.vbs
==========
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "c:\jeff\insteon\temp.bat", 0
==========
The Powerhome command runs, but temp.bat never gets executed....
Thanks anyhoo. - probably something weird on my end
|
Back to Top |
|
|
gg102 Senior Member
Joined: January 29 2013 Location: United States
Online Status: Offline Posts: 245
|
Posted: February 24 2017 at 19:34 | IP Logged
|
|
|
Jeff_w
Try adding the debug line:
msgbox("DEBUG MSG: About to run the ping .BAT program
in the background")
to make sure it's getting launched.
|
Back to Top |
|
|
jeffw_00 Super User
Joined: June 30 2007
Online Status: Offline Posts: 929
|
Posted: February 24 2017 at 21:00 | IP Logged
|
|
|
you're right - the Powerhome command returns
***INITIAIZE ERROR - Filename: c:\jeff\insteon\temp.vbs | Function: | Source | Error Number: 0|Description: |Line: 0| Column: 0| Text ***
Unfortunately I know zero about Visual Basic, so....
thoughts?
thanks!
/j
|
Back to Top |
|
|
gg102 Senior Member
Joined: January 29 2013 Location: United States
Online Status: Offline Posts: 245
|
Posted: February 24 2017 at 21:10 | IP Logged
|
|
|
You're not going to believe this, but that's correct.
That's what PH does when running this script. The
important part is "Error Number: 0"
Let me check something tonight.
I'm not all that good on VBS, but this is running on my
machine, so I'll trace it through.
It's been a few years since I invented this..
|
Back to Top |
|
|
jeffw_00 Super User
Joined: June 30 2007
Online Status: Offline Posts: 929
|
Posted: February 24 2017 at 21:14 | IP Logged
|
|
|
I'll believe it :-)
thanks in advance for anything you find!
/j
|
Back to Top |
|
|
gg102 Senior Member
Joined: January 29 2013 Location: United States
Online Status: Offline Posts: 245
|
Posted: February 24 2017 at 21:26 | IP Logged
|
|
|
ok, here's what's happening...
WshShell.Run "c:\jeff\insteon\temp.bat", 0
launches the .bat hidden. It can't "ECHO" anything
because it's hidden.
To "watch" the .BAT, change the line to:
WshShell.Run "c:\jeff\insteon\temp.bat", 1
This will allow you to see the .BAT popup.
Put these lines in your .BAT
ECHO This is the DOS POPUP
Pause
This should show you the .BAT
If the popup happens, your .BAT did run.
|
Back to Top |
|
|
jeffw_00 Super User
Joined: June 30 2007
Online Status: Offline Posts: 929
|
Posted: February 24 2017 at 22:36 | IP Logged
|
|
|
I know my BAT runs because I can run it standalone, and I have other ways of telling when it runs (it updates a file). I don't know if PH isn't triggering the VBS, or the VBS isn't triggering the BAT, but one or the other is true.... I think it's the former because we're not seeing the debug statement in the VBS?
Thanks!
/j
|
Back to Top |
|
|
gg102 Senior Member
Joined: January 29 2013 Location: United States
Online Status: Offline Posts: 245
|
Posted: February 24 2017 at 23:40 | IP Logged
|
|
|
Let me ask a simple question....
In "Preferences" do you have "load script server" enabled?
|
Back to Top |
|
|
jeffw_00 Super User
Joined: June 30 2007
Online Status: Offline Posts: 929
|
Posted: February 25 2017 at 08:40 | IP Logged
|
|
|
Oh, THAT's what that checkbox is for :-) (sigh).
Ok - checking the box, and discovering that I can actually click on the .vbs file directly for debug....
all working now - thanks so much for your help,and I learned something :-)
/j
|
Back to Top |
|
|
Resolute Newbie
Joined: January 11 2016
Online Status: Offline Posts: 32
|
Posted: June 08 2017 at 22:31 | IP Logged
|
|
|
Below is a sub that spawns a silent windows process. Just pass a command string to the sub (this one queries a hue light for its status). I
had to add the quotes with the chr() function because of cURL's needs. The process runs silently as a windows process (not in a command
window). If you need to pass responses back, the best way is to output the process to a file (below it uses the -o option in cURL), then
read the file back into the script using the filesystem object, then pass that back to PH via the calling function, or directly to PH using
a ph.xxx function (my preference).
(This is all contained in a VBS function library file called by a ph_runscript_n function)
Execute ("curl.exe -o huestatus.txt -H " & chr(34) & chr(32) & "Accept: application/json" & chr(34) & chr(32) &
"http://192.168.0.197/api/pwrhomeuser/lights/" + LightID)
Sub Execute(Command)
Const HIDDEN_WINDOW = 0
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW
Set objProcess = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
objProcess.Create Command, null, objConfig, intProcessID
End Sub
Enjoy!
|
Back to Top |
|
|