Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Feature Requests
 PowerHome Messageboard : PowerHome Feature Requests
Subject Topic: ph_run command Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: December 25 2015 at 09:30 | IP Logged Quote smarty

Low priority feature request...

It would be more asthetically pleasing if the ph_run() command could have the ability to run "silently", so as to NOT have a shell window open (even if it is open for just a quick flash).

I use a number of small command line utilities to perform certain tasks...not having the shell flash on/off the screen would be a nice addition.

Utilities that I use include:
telenet
display.exe
nircmd.exe
cURL.exe

Just a possible suggestion....

__________________
Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
Back to Top View smarty's Profile Search for other posts by smarty
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: January 04 2016 at 20:43 | IP Logged Quote dhoward

Steve,

I've made a note to my todo list to look into this.

I'll keep you posted.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: January 25 2016 at 10:00 | IP Logged Quote gg102

Hi Smarty,
Sorry for not responding sooner, I've been "away" for a while.

There is another way to run a .BAT silently.

Rather than doing this:
ph_run("c:\MyDirectory\myfunction.bat")

Do this:
ph_runscript_0 ( 100, "c:\MyDirectory\myfunction.vbs", "" )


Your .VBS code will be like this: (you can cut and paste this as a template)

'----------------------
' msgbox("About to run the MyFunction .BAT program silently in the background")
'
Set WshShell = CreateObject("WScript.Shell")
'
'REM Now, run the .bat hidden....
WshShell.Run "c:\MyDirectory\myfunction.bat", 0
' All done
'----------------------

You MIGHT see a window pop up and then it will disappear quickly. This depends on how fast your system and video system works. Usually, you'll not see anything.

Please remember that when running an external process outside of PH, the functiuon will be asynchronous to PH, and you might run into a timing issue. To retrieve data, I use the PH utility "FileMon" to determine when a file is ready to use. Just be sure to have a "JUMP if (ph_fileexists( "c:\MyDirectory\myfunction.txt" )=1,1,999)" in your code or you could end up processing a file that has just been deleted.

Just my humble thoughts...
Your mileage may vary.

Back to Top View gg102's Profile Search for other posts by gg102
 
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: January 25 2016 at 15:36 | IP Logged Quote smarty

Thank you for the suggestion....I will give this a look and try..

__________________
Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
Back to Top View smarty's Profile Search for other posts by smarty
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: January 25 2016 at 22:37 | IP Logged Quote dhoward

gg,

Appreciate you chiming in on this. Hadnt thought of
this method before but after taking a quick look
definitely seems like a reasonable option (I'll still
look to see if I can do this from within a PH
function).

Below is a sample based upon gg's code that may make
it a little more straightforward:

ph_executescript(-1,"",'CreateObject("Wscript.Shell").Run "yourbatchfile.bat", 0, True')

No need to create the vbs file and just a single line
to execute. In my testing, it did not popup a command
window.

Let me know how it works for you.

Dave.


Edited by dhoward - January 25 2016 at 22:40
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: January 26 2016 at 09:45 | IP Logged Quote gg102

Hi Dave,

You offer a much simpler method.

I tried your sggestion and discovered that it remains synchronous. Using your method, the function waits until the external .BAT completes. My method starts a new thread and allows PH to continue.

So, I guess it depends on how a programmer wants to handle an external process.

For myself, I don't like suspending a main thread waiting for an external process to complete JIC something bad happens/crashes. While your method does have a timeout option, PH would be suspended until the timeout hits.

Both methods work.




Back to Top View gg102's Profile Search for other posts by gg102
 
Resolute
Newbie
Newbie
Avatar

Joined: January 11 2016
Online Status: Offline
Posts: 32
Posted: February 03 2016 at 23:14 | IP Logged Quote Resolute

Hey Smarty

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!

Edited by Resolute - February 03 2016 at 23:25
Back to Top View Resolute's Profile Search for other posts by Resolute
 
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: March 06 2016 at 23:25 | IP Logged Quote smarty

Many thanks!


__________________
Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
Back to Top View smarty's Profile Search for other posts by smarty
 
Baumgardner
Newbie
Newbie
Avatar

Joined: September 26 2017
Online Status: Offline
Posts: 1
Posted: October 08 2017 at 02:54 | IP Logged Quote Baumgardner

This helped me a lot too Resolute. Thanks for sharing!
Back to Top View Baumgardner's Profile Search for other posts by Baumgardner
 
Resolute
Newbie
Newbie
Avatar

Joined: January 11 2016
Online Status: Offline
Posts: 32
Posted: July 05 2018 at 10:08 | IP Logged Quote Resolute

Update to silent process sub: Not sure how this got posted without the "Set [object] = nothing" lines, sorry!! Without those cleanup
lines it is unpredictable what effects it will have on the system over time, especially with those like myself that poll the hue bridge
for all lights and groups every 2 seconds!

Here it is with the changes:

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
     Set objProcess = nothing
     Set objConfig = nothing
     Set objStartup = nothing
     Set objWMIService = nothing
End Sub

Enjoy!
Back to Top View Resolute's Profile Search for other posts by Resolute
 
Villaria 03
Newbie
Newbie


Joined: June 22 2022
Location: Austria
Online Status: Offline
Posts: 1
Posted: July 04 2022 at 15:40 | IP Logged Quote Villaria 03

Thanks for sharing helpful details. It helped me solve
problems.


Edited by Villaria 03 - July 27 2022 at 03:28


__________________
phenq interdit en france
Back to Top View Villaria 03's Profile Search for other posts by Villaria 03
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum