| Author |  | 
      
        | smarty Super User
 
  
  
 Joined: May 21 2006
 Location: United States
 Online Status: Offline
 Posts: 729
 | 
          Low priority feature request...
           | Posted: December 25 2015 at 09:30 | IP Logged |   |  
           | 
 |  
 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 |     | 
       
       
        |  | 
        | dhoward Admin Group
 
  
  
 Joined: June 29 2001
 Location: United States
 Online Status: Offline
 Posts: 4447
 | 
          Steve,
           | Posted: January 04 2016 at 20:43 | IP Logged |   |  
           | 
 |  
 I've made a note to my todo list to look into this.
 
 I'll keep you posted.
 
 Dave.
 
 | 
       
        | Back to Top |       | 
       
       
        |  | 
        | gg102 Senior Member
 
  
 
 Joined: January 29 2013
 Location: United States
 Online Status: Offline
 Posts: 246
 | 
          Hi Smarty,
           | Posted: January 25 2016 at 10:00 | IP Logged |   |  
           | 
 |  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 |     | 
       
       
        |  | 
        | smarty Super User
 
  
  
 Joined: May 21 2006
 Location: United States
 Online Status: Offline
 Posts: 729
 | 
          Thank you for the suggestion....I will give this a look and try..
           | Posted: January 25 2016 at 15:36 | IP Logged |   |  
           | 
 |  
 __________________
 Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | dhoward Admin Group
 
  
  
 Joined: June 29 2001
 Location: United States
 Online Status: Offline
 Posts: 4447
 | 
          gg,
           | Posted: January 25 2016 at 22:37 | IP Logged |   |  
           | 
 |  
 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 |       | 
       
       
        |  | 
        | gg102 Senior Member
 
  
 
 Joined: January 29 2013
 Location: United States
 Online Status: Offline
 Posts: 246
 | 
          Hi Dave,
           | Posted: January 26 2016 at 09:45 | IP Logged |   |  
           | 
 |  
 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 |     | 
       
       
        |  | 
        | Resolute Newbie
 
  
  
 Joined: January 11 2016
 Online Status: Offline
 Posts: 32
 | 
          Hey Smarty
           | Posted: February 03 2016 at 23:14 | 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!
 
 Edited by Resolute - February 03 2016 at 23:25
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | smarty Super User
 
  
  
 Joined: May 21 2006
 Location: United States
 Online Status: Offline
 Posts: 729
 | 
          Many thanks!
           | Posted: March 06 2016 at 23:25 | IP Logged |   |  
           | 
 |  
   
 __________________
 Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Baumgardner Newbie
 
  
  
 Joined: September 26 2017
 Online Status: Offline
 Posts: 1
 | 
          
           | Posted: October 08 2017 at 02:54 | IP Logged |   |  
           | 
 |  
| gg102 wrote: 
 
    
    | 
      
       | Hi Dave, 
 You offer a much  simpler method.
 
 I
 review/">recently tried phenq 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.
 
 
 
 
 
 |  |  |  
 This helped me a lot too Resolute. Thanks for sharing!
 
 Edited by Baumgardner - January 29 2025 at 04:40
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Resolute Newbie
 
  
  
 Joined: January 11 2016
 Online Status: Offline
 Posts: 32
 | 
          Update to silent process sub: Not sure how this got posted without the "Set [object] = nothing" lines, sorry!! Without those cleanup
           | Posted: July 05 2018 at 10:08 | IP Logged |   |  
           | 
 |  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 |     | 
       
       
        |  | 
        | Villaria 03 Newbie
 
  
 
 Joined: June 22 2022
 Location: Austria
 Online Status: Offline
 Posts: 1
 | 
          Thanks for sharing helpful details. It helped me solve
           | Posted: July 04 2022 at 15:40 | IP Logged |   |  
           | 
 |  problems.
 
 
 Edited by Villaria 03 - July 27 2022 at 03:28
 
 __________________
 phenq interdit en france
 | 
       
        | Back to Top |     | 
       
       
        |  |