How to issue a command line instruction. [SOLVED]

Windows specific forum
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

How to issue a command line instruction. [SOLVED]

Post 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
Last edited by davebar on Fri Jul 16, 2021 9:04 pm, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to issue a command line instruction.

Post by mk-soft »

Show PB Help RunProgram
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
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

Re: How to issue a command line instruction.

Post 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
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: How to issue a command line instruction.

Post 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.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: How to issue a command line instruction.

Post 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()?
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

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

Post 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
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

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

Post 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.
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

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

Post 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
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

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

Post 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)
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

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

Post 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
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

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

Post 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
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

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

Post 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
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to issue a command line instruction.

Post by Caronte3D »

davebar wrote: Fri Jul 16, 2021 8:55 pm Obviously PB lacks his trivially simple facility, so...
:lol: :lol: :lol:
davebar
User
User
Posts: 82
Joined: Fri Aug 31, 2018 9:23 am
Location: Australia

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

Post 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.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

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

Post by Caronte3D »

Put a bit of humour in your life man :wink:
Post Reply