topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 5:48 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Command-Line Shooter  (Read 3338 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 552
    • View Profile
    • Donate to Member
Command-Line Shooter
« on: September 16, 2020, 12:44 AM »
I have a list of command.com 'things' I want to execute.  Let's say, 300+.

One command.com 'order' per line.

Presently all 300+ are in one long text file.

Imagine, as metaphor, all 300+ are like bullets on a belt.

Belt of bullets.jpgCommand-Line Shooter

I need the 'gun'.

In other words, I'd like to rip off the top, say, 10.  Put them in the gun.  Pull the trigger.

Boom, boom, boom.....

All ten command.com lines get executed, one after another.

Okay, I could make up separate batch files for each group.  But it would be faster to do it some other way.

Enter:  Command-Line Shooter

Thoughts appreciated.

Nicholas Kormanik



KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Command-Line Shooter
« Reply #1 on: September 16, 2020, 01:37 AM »
Good day nkormanik,

I do not fully understand your slang text.
Could you be nice and re-write it in a more technical specific way?

What I understood is, you like to execute something.
What I understood is, you have alot of commands.

What is missing:
What should your request do? Technical informations are required.
(Load a text file "file.txt" and parse each line to command.com interpreter?)

Best would be, upload an example file with content that you like to execute/shoot/bang boom zang

//edit
Should your request become a GUI or would a command line version fit?
How should program work?
Commandline version example:
"shooter.exe /file=input.txt /begin=10 /end=100"
stand for "use input.txt" "from line 10" up to "line 100" execute.
Is such what you need?
« Last Edit: September 16, 2020, 06:34 AM by KodeZwerg »

Shades

  • Member
  • Joined in 2006
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Command-Line Shooter
« Reply #2 on: September 16, 2020, 11:26 AM »
Then you must hope that everything you wish to execute this way is correctly formatted. If not, it messes up the ability of shooter.exe to finish completing the set of (single line) command.

If there are 300+ single line batch commands to execute...there has to be some logic behind them. Because if not, it will become a mess. Maybe not today, but in the near future it will.

If there are 300+ single line batch commands to execute...when is the optimum time to execute these? If based on certain conditions, it won't be easy. In fact, you'll need a separate interpreter for the conditions as well. Not only shooter.exe, but also ammobox.exe. And by that time you are creating software akin to AHK or AutoIt. While KodeZwerg might like to create AHKodeZwerg or something similar, nkormanik is too hung up on using batch scripts for anything.

If there are 300+ single line batch commands to execute...nkormanik should store these as snippets instead and create simple batch scripts that CALL the appropriate snippet at the optimum time. Or start to learn about PowerShell, which is much better equipped to handle his request than the command.com interpreter.
 


wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,186
    • View Profile
    • Donate to Member
Re: Command-Line Shooter
« Reply #3 on: September 16, 2020, 01:02 PM »
If it's as simple as you're saying, you don't even need a program to do it for you.  It's already built into windows.

Code: PowerShell [Select]
  1. Get-Content -Path "path-to-text-file.txt" | ForEach-Object {
  2.     $args = $_.Split(' ', 2)
  3.     Start-Process -FilePath $args[0] -ArgumentList $args[1]
  4.     }

Open a text editor, put that code snippet in, name it something.ps1, create a text file with your commands in it, and it will run them in order, spawning them in different processes.  If you want them to be dependent on each other, that's a different problem.  But each bullet in a bandolier isn't dependent on the others, so this fits the analogy.  ;) :Thmbsup:

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,347
    • View Profile
    • Donate to Member
Re: Command-Line Shooter
« Reply #4 on: September 16, 2020, 05:55 PM »
i was just thinking about this last week.
What I ended up going with is mouser's launchbar commander...
I create a button for the commands or group of commands i'd want to launch.  Works great!
It will take some time setting up, but then you can a menu and buttons to do whatever you want.


I think AHK is also good for this sort of thing, but I'm a gui guy.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,641
    • View Profile
    • Donate to Member
Re: Command-Line Shooter
« Reply #5 on: September 16, 2020, 08:04 PM »
Code: Text [Select]
  1. for /f "tokens=* delims=" %x in (test.txt) do start "" cmd.exe /C %x

FYI
« Last Edit: September 16, 2020, 08:09 PM by 4wd »

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Command-Line Shooter
« Reply #6 on: September 17, 2020, 01:28 AM »
Due missing part "file.txt content example" I just coded an application that is capable to execute or open files.

Shooter v0.1 by KodeZwerg

Manual

shooter is a window console application, driven by parameters only.
possible parameters are /file="Filename" /begin=X /end=Y /loop=Z


parameter description
/file=
fill that parameter with a quoted "path\filename.ext" value.
my application does not need to be in same folder of "path\filename.ext".
"Filename" must be a plaintext textfile,
where every line lead to a qualified "path\filename.ext" file.
(missing quotes inside textfile are auto-generated)

/begin=
tell my program at which line it should begin
default is line #1

/end=
tell my program at which line it should end
if using /loop, this parameter has no effect
default is end of file

/loop=
tell my program how many times it should loop



Examples:
shooter.exe /file=test.txt [return]
that would call my app to try execute every line inside test.txt

shooter.exe /file=test.txt /begin=2 [return]
that would call my app to try execute every line, beginning with line 2 inside test.txt

shooter.exe /file=test.txt /end=2 [return]
that would call my app to try execute every line inside test.txt until line 2 is reached

shooter.exe /file=test.txt /loop=2 [return]
that would call my app to try execute every line inside test.txt until line 2 is reached

shooter.exe /file=test.txt /begin=2 /end=6 [return]
that would call my app to try execute lines 2-6 inside test.txt

shooter.exe /file=test.txt /begin=2 /loop=4 [return]
that would call my app to try execute lines 2-6 inside test.txt


i hope that is enough explaination.
enjoy another KodeZwerg production.


if anything goes wrong, my app will inform you with "Error: " message inside console.
it will not stop if an error occured during execution phase.

//edit
for your information, this app does not use command.com interpreter, it invoke ShellExecuteEx() from Windows Api to do it's job.
« Last Edit: September 17, 2020, 02:17 AM by KodeZwerg »

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Command-Line Shooter
« Reply #7 on: September 17, 2020, 02:25 AM »
Then you must hope that everything you wish to execute this way is correctly formatted. If not, it messes up the ability of shooter.exe to finish completing the set of (single line) command.
my app simple say "Error: unable to find x y z" or something like that.


If there are 300+ single line batch commands to execute...there has to be some logic behind them. Because if not, it will become a mess. Maybe not today, but in the near future it will.
i'd thought about to include a /wait=X parameter, to wait X ms between next call.
aslong ShellExecuteEx() is okay to be used, i also could integrate a /WaitUntilExecutionEnds switch.

While KodeZwerg might like to create AHKodeZwerg
i love your fantasy "AHK....odeZwerg"  :Thmbsup:
but in fact i do have no clue about script languages. i try to avoid them ;)
« Last Edit: September 17, 2020, 02:37 AM by KodeZwerg »