Page 1 of 2

How to issue a command line instruction. [SOLVED]

Posted: Fri Jul 16, 2021 2:09 pm
by davebar
I am trying to find a way to issue a simple command line instruction to Windows from within a PB program.

TIA
Dave

Re: How to issue a command line instruction.

Posted: Fri Jul 16, 2021 6:23 pm
by mk-soft
Show PB Help RunProgram

Re: How to issue a command line instruction.

Posted: Fri Jul 16, 2021 8:55 pm
by davebar
Thanks mk-soft, but RunProgram is not a solution to my issue.

I need to be able to issue a command in exactly the same way as if I opened the the windows command prompt and entered the command.

I am not running a program, I am issuing a direct Windows command line.

Obviously PB lacks his trivially simple facility, so I have resolved the issue with other software.

Regards
Dave

Re: How to issue a command line instruction.

Posted: Sat Jul 17, 2021 12:44 am
by Demivec
davebar wrote: Fri Jul 16, 2021 8:55 pm Thanks mk-soft, but RunProgram is not a solution to my issue.

I need to be able to issue a command in exactly the same way as if I opened the the windows command prompt and entered the command.

I am not running a program, I am issuing a direct Windows command line.

Obviously PB lacks his trivially simple facility, so I have resolved the issue with other software.
Why not try the following trvially simple facility?

Code: Select all

RunProgram("cmd.exe", "/c dir | more", GetPathPart(ProgramFilename()))
The above demonstrates issuing a direct WIndows command line to list a directory's contents. I would think other commands would function as well.

Re: How to issue a command line instruction.

Posted: Sat Jul 17, 2021 1:08 am
by BarryG
davebar wrote: Fri Jul 16, 2021 8:55 pmI need to be able to issue a command in exactly the same way as if I opened the the windows command prompt and entered the command.
RunProgram() can do that; I do it all the time to match command prompt queries. It's no problem to do and works great.
davebar wrote: Fri Jul 16, 2021 8:55 pmObviously PB lacks his trivially simple facility
Not true at all. Why don't you post your command-line text and we'll show you how to do it with RunProgram()?

Re: How to issue a command line instruction. [SOLVED]

Posted: Sat Jul 17, 2021 9:17 am
by davebar
I hadn't intended to pursue this issue, but since a number of experienced PB users claim RunProgram will work, I would be interested to know how to do the following.
Run cmd.exe and have the Ver instruction display the version in the interpreter window.
I am only using the Ver instruction here as an example, because my real instruction would have raised too many "red herrings" [1]

Regards
Dave

[1] Definition: https://en.wikipedia.org/wiki/Red_herring

Re: How to issue a command line instruction. [SOLVED]

Posted: Sat Jul 17, 2021 11:43 am
by BarryG
davebar wrote: Sat Jul 17, 2021 9:17 amRun cmd.exe and have the Ver instruction display the version in the interpreter window
Here:

Image

RunProgram() result:

Image

The code that did it with RunProgram():

Code: Select all

Compiler = RunProgram("cmd.exe", " /c ver", "", #PB_Program_Hide | #PB_Program_Open | #PB_Program_Read)

If Compiler
  While ProgramRunning(Compiler)
    If AvailableProgramOutput(Compiler)
      Output$ + ReadProgramString(Compiler) + Chr(13)
    EndIf
  Wend
  Output$ + Chr(13) + Chr(13)
  CloseProgram(Compiler)
EndIf

MessageRequester("Output", Output$)
So you can see, PB does not lack this trivially simple facility at all. Just ask for help if you need it - we're here for you!

BTW, I don't care about red herrings or such... so if you still can't get your thing to work with RunProgram(), ask here and I'll see what's going wrong.

Re: How to issue a command line instruction. [SOLVED]

Posted: Sat Jul 17, 2021 3:04 pm
by davebar
Sorry this does not do what I was asking for.
I want the Windows version to appear and stay visible ONLY in the the command line window, without the MessageRequester.
Your code gives me the output ONLY in the MessageRequester and NO output in the command line window.

Regards
Dave

Re: How to issue a command line instruction. [SOLVED]

Posted: Sat Jul 17, 2021 4:10 pm
by Mijikai
davebar wrote: Sat Jul 17, 2021 3:04 pm ...
I want the Windows version to appear and stay visible ONLY in the the command line window, without the MessageRequester.
...
Just that or what?

Code: Select all

RunProgram("cmd.exe", " /k ver",#Null$,#PB_Program_Open)

Re: How to issue a command line instruction. [SOLVED]

Posted: Sat Jul 17, 2021 4:38 pm
by davebar
OK, Real progress. I replace your "/k ver" with "/k <my command line string>" and it works perfectly.
I now need to construct a string variable eg Command$ in order to get:

Code: Select all

RunProgram("cmd.exe", Command$, #Null$, #PB_Program_Open)
to do exactly the same thing.

Any thoughts?

Many thanks for your time and patience.

Regards
Dave

Re: How to issue a command line instruction. [SOLVED]

Posted: Sat Jul 17, 2021 4:47 pm
by Mijikai
Example:

Code: Select all

EnableExplicit

Procedure.i RunCMD(Command.s)
  ProcedureReturn Bool(RunProgram("cmd.exe"," /k " + Command,#Null$) <> #Null)
EndProcedure

Debug RunCMD("ver")

End

Re: How to issue a command line instruction. [SOLVED]

Posted: Sat Jul 17, 2021 5:11 pm
by davebar
Wow! And I thought Assembler and C++ were complicated to understand.

It's going to take me some time to figure out why this works in a procedure.

Again, thanks to all who contributed to this thread.

Regards
Dave

Re: How to issue a command line instruction.

Posted: Sat Jul 17, 2021 5:46 pm
by Caronte3D
davebar wrote: Fri Jul 16, 2021 8:55 pm Obviously PB lacks his trivially simple facility, so...
:lol: :lol: :lol:

Re: How to issue a command line instruction. [SOLVED]

Posted: Sat Jul 17, 2021 7:07 pm
by davebar
It comes as no surprise that the FANBOYS who contributed nothing to this thread would jump in with derogatory commentary after the fact. But sadly that's the way the world is today and one of the main reasons I stopped following this forum.

Re: How to issue a command line instruction. [SOLVED]

Posted: Sat Jul 17, 2021 7:32 pm
by Caronte3D
Put a bit of humour in your life man :wink: