open console hidden, send command to, return data from it?
open console hidden, send command to, return data from it?
Hi all! So I'm trying to open a console window but open it hidden, send a command to NodeJS & return the data into the program from it.
How is this possible?
Any help is GREATLY appreciated!
Thanks! <3
How is this possible?
Any help is GREATLY appreciated!
Thanks! <3
Re: open console hidden, send command to, return data from i
Someone can help?
Re: open console hidden, send command to, return data from i
Yon don't net OpenConsole for this.
You can use RunProgram and OpenWindow with flag #PB_Window_Invisible
You can use RunProgram and OpenWindow with flag #PB_Window_Invisible
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: open console hidden, send command to, return data from i
Code: Select all
Procedure.s GetCommandOutput(Command$, Parameter$, *ExitCode = 0)
Define Output$
Define ThisCommand.i
ThisCommand = RunProgram(Command$, Parameter$, "Your Path here", #PB_Program_Open | #PB_Program_Hide | #PB_Program_Read)
Output$ = ""
If (ThisCommand <> 0)
While ProgramRunning(ThisCommand)
If AvailableProgramOutput(ThisCommand)
Output$ + ReadProgramString(ThisCommand) + Chr(13)
EndIf
Wend
If (*ExitCode <> 0)
PokeI(*ExitCode, ProgramExitCode(ThisCommand))
EndIf
CloseProgram(ThisCommand) ; Close the connection to the program
EndIf
ProcedureReturn Output$
EndProcedure
Re: open console hidden, send command to, return data from i
I am trying to send a command to node js & then after that, return the data back.
Re: open console hidden, send command to, return data from i
This code seems to work, but for some reason is not passing the nodejs ".help" parameter to the cmd :
Code: Select all
Procedure.s GetCommandOutput ( Command$, Parameter$, *ExitCode = 0 )
Define Output$
Define ThisCommand.i
ThisCommand = RunProgram ( Command$, Parameter$, "/", #PB_Program_Open | #PB_Program_Hide | #PB_Program_Read | #PB_Program_Hide )
Output$ = ""
If ( ThisCommand <> 0 )
While ProgramRunning ( ThisCommand )
If AvailableProgramOutput ( ThisCommand )
Output$ + ReadProgramString ( ThisCommand ) + Chr ( 13 )
Break
EndIf
Wend
; Close the connection to the program
CloseProgram ( ThisCommand )
EndIf
ProcedureReturn Output$
EndProcedure
cmd$ = GetCommandOutput ( "node", ".help", 0 )
Debug ( cmd$ )
Re: open console hidden, send command to, return data from i
Maybe the resulting error code would tell you, but you dont handle it. My guess would be that the executable can't be found because of the path.
Re: open console hidden, send command to, return data from i
Change
To
and check what the errorcode says. If my guess is right, your "node" command simply can't be found. The errorcode should give you a clue. Always evaluate the return codes at least when a problem shows up and during the initial development. Shortcuts in your code can come later when it works and is tested for years 
Code: Select all
cmd$ = GetCommandOutput ( "node", ".help", 0 )
Code: Select all
define CmdErrorCode.i
cmd$ = GetCommandOutput ( "node", ".help", @CmdErrorcode )

Re: open console hidden, send command to, return data from i
It returned '0' however, my node js does exist. i just typed node into the command prompt & it said welcome to node.
Re: open console hidden, send command to, return data from i
This code snippet saves a JavaScript file in the Temp folder and executes it with Node:
Code: Select all
EnableExplicit
Define TempJsFilename.s = GetTemporaryDirectory() + "temp.js"
CreateFile(0, TempJsFilename)
WriteStringN(0, "console.log('hello from node');")
CloseFile(0)
Define Dummy.s
Define RPE.s ; ReadProgramError
Define RPS.s ; ReadProgramString
Define Exitcode
Define NodeJs = RunProgram("cmd.exe", "/c node " + Chr(34) + TempJsFilename + Chr(34), "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Error | #PB_Program_Hide)
If NodeJs
While ProgramRunning(NodeJs)
Dummy = ReadProgramError(NodeJs)
If Dummy
RPE + Dummy + #CRLF$
EndIf
Dummy = ReadProgramString(NodeJs)
If Dummy
RPS + Dummy + #CRLF$
EndIf
Wend
Exitcode = ProgramExitCode(NodeJs)
CloseProgram(NodeJs) ; Close the connection to the program
EndIf
Define Output.s
If RPS <> ""
Output + "ReadProgramString: " + #CRLF$ + RPS + #CRLF$
EndIf
If RPE <> ""
Output + "ReadProgramError: " + #CRLF$ + RPE + #CRLF$
EndIf
If Exitcode <> 0
Output + "ExitCode: " + Exitcode + #CRLF$
EndIf
MessageRequester("", Output)
DeleteFile(TempJsFilename)
Hygge
Re: open console hidden, send command to, return data from i
I thought it was Node I needed, apparently not. I'm trying to send a command to JSDocs with some stored file to & from locations so I can overwrite some documentation I am writing for a library I made. Then read the data it returns back into my program.
Re: open console hidden, send command to, return data from i
Mythros wrote:I thought ...

Hygge