Author Topic: Passing variables via command line  (Read 9965 times)

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Passing variables via command line
« on: July 06, 2020, 04:21:03 PM »
You can call commands from the command line (or another application), but you cannot pass it any variables.

Being able to do so would be a great improvement over my current clipboard dancing shenanigans :)

TheThingIs

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 278
    • HCS Voicepacks
Re: Passing variables via command line
« Reply #1 on: July 07, 2020, 01:32:00 AM »
Generally when you run a program via the cmd line you pass it variables/options via tagging them onto the run cmd. i.e "VoiceAttack.exe -asadmin" and VA supports this. The program you are running also needs to support this. AFAIK that is the only way to pass info to 3rd party apps unless they've specifically allowed some other method, which would be in their documentation.
The Singularity profile - One profile to rule them all and at HCS we bound them ;)

You see, TheThingIs, eventually you'll be allright.

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #2 on: July 07, 2020, 02:33:14 AM »
Generally when you run a program via the cmd line you pass it variables/options via tagging them onto the run cmd. i.e "VoiceAttack.exe -asadmin" and VA supports this.

There is no way to pass e.g. “-string testvar "some text"”. Or is there? :)

TheThingIs

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 278
    • HCS Voicepacks
Re: Passing variables via command line
« Reply #3 on: July 08, 2020, 11:46:04 AM »
yes you put that as the full command you want to run and they will be passed as long as the program you are running supports passing those items
The Singularity profile - One profile to rule them all and at HCS we bound them ;)

You see, TheThingIs, eventually you'll be allright.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Passing variables via command line
« Reply #4 on: July 08, 2020, 11:51:03 AM »
As I understand it, the idea is to pass variables to VoiceAttack when executing a command using the "-command" argument.

This is not currently possible.


You can use different command phrases for different preset outcomes (E.G. if you have a command "turn the lights [on;off]" you can use -command "turn the lights on" or "turn the lights off", in combination with the "{CMD}" token to affect the flow of the command), but there is no facility for passing arbitrary information using command line parameters.

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #5 on: July 08, 2020, 01:52:46 PM »
You can use different command phrases for different preset outcomes (E.G. if you have a command "turn the lights [on;off]" you can use -command "turn the lights on" or "turn the lights off", in combination with the "{CMD}" token to affect the flow of the command)

I know, but that really doesn’t work when things get more complex. Hence me having to fight with the Windows clipboard right now.

Edit: being the maniac that I am I have now tested calling wild card commands from the command line. But that doesn’t work :)
« Last Edit: July 09, 2020, 01:13:27 PM by alterNERDtive »

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #6 on: July 13, 2020, 05:24:05 PM »
For the record, my current workaround now involves my IRC client writing the message to a file and invoking the command, and VoiceAttack reading that file to the variable, then deleting it. Well, it “works”.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Passing variables via command line
« Reply #7 on: July 13, 2020, 06:15:27 PM »
It's an interesting concept.  I'll put it on the list and if others out there can make application of such a feature I'll be sure to look into it!

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #8 on: July 15, 2020, 02:19:46 AM »
You could potentially even tie it into the new feature to pass parameters with command invocations :)

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Passing variables via command line
« Reply #9 on: July 15, 2020, 09:23:19 AM »
The mods were actually discussing exactly that type of implementation over in Discord - might make a pass at it.  I don't have an ETA, though :(

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Passing variables via command line
« Reply #10 on: July 26, 2020, 01:20:45 AM »
This has been added to the latest beta - give 'er a try!

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #11 on: July 30, 2020, 09:43:36 PM »
I will!

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #12 on: July 31, 2020, 12:22:46 AM »
Hmm. Not sure if I’m misunderstanding something …

So far I can make “~passedInteger1”, “~passedDecimal1” and “~passedBoolean1” work (by passing them without a number, as per update notes). Trying to pass more than one of a type does not work (TBF, only tested with Integer).

I also cannot seem to make “~passedText1” work in any way.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Passing variables via command line
« Reply #13 on: July 31, 2020, 12:36:12 AM »
Have you read the documentation on passing variables to commands, which is the basis of this feature?

Passing multiple integer values works on my machine; Note that each parameter should only be used once (E.G. you can't do '-PassedInteger "1" -PassedInteger "2"')


However, passing literal text does not appear to work (though passing text variable names does). Even the example in the documentation ('-PassedText """"Hello""""') did not work on my machine.

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #14 on: July 31, 2020, 02:29:07 AM »
Well would you look at that. You might have given a condescending answer again, but you got me on the right track.

-passedText "\"text here\"" works. So does -passedText "\"one\";\"two\"".

Might or might not be intentional. Other combinations of trying to use outer " and inner ' or vice versa didn’t work.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Passing variables via command line
« Reply #15 on: July 31, 2020, 08:20:15 AM »
I didn't find that condescending.


I'll take a look at the literal situation for text - it wont be until after the weekend, though.

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #16 on: July 31, 2020, 12:34:15 PM »
I have another observation for you. I think it’s an issue with how external command invocation is handled in general though.

So I have made a test command as shown in the first screenshot. I am then invoking it 5 times in rapid succession with “one” through “five” as parameters. Resulting log output in the second screenshot.

It works just fine if it is done in sequence (e.g. waiting for the VoiceAttack invocation to return, then doing the next one).

Quote
it wont be until after the weekend, though

NP, I’ll keep doing silly stuff VA was never made for in the mean time :)

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Passing variables via command line
« Reply #17 on: July 31, 2020, 01:34:08 PM »
Instances may be stepping on each other / race condition.  Since the parameters can be passed to the running instance or the loading instance, this could be a problem.  I'll need to look into it further, as VA wasn't designed to be slammed like that from the command line.  There's a good chance that what you're trying to do will require you to build a plugin so you can get data in and out of VA in a rapid fashion (that is, we're kind of on the fringe here and a little outside of VA's scope).

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #18 on: July 31, 2020, 01:53:04 PM »
Yeah, I can see it being out of scope. I started running into this limitation when invoking commands from IRC events and I had a couple right after each other.

If you declare it flat out as “out of scope” I’ll have to find a way to make sure on my end that I don’t trip over it.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4782
  • RTFM
Re: Passing variables via command line
« Reply #19 on: July 31, 2020, 02:10:06 PM »
You might have given a condescending answer again

You stated:
Hmm. Not sure if I’m misunderstanding something …

So far I can make “~passedInteger1”, “~passedDecimal1” and “~passedBoolean1” work (by passing them without a number, as per update notes). Trying to pass more than one of a type does not work (TBF, only tested with Integer).
From which I inferred you had read the change log, but perhaps not the documentation, and that you were likely using multiple instances of the same command line parameter, rather than a single instance with the intended syntax.

Therefore, I asked:
Have you read the documentation on passing variables to commands, which is the basis of this feature?

As the section in the documentation on the original feature shows that it is intended to be used with a single string of text, from which the input will be parsed (there is only one input field per type, which further demonstrates this), which would likely make clear to you why what you were attempting to do would not work.


I don't see the condescension in that.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Passing variables via command line
« Reply #20 on: August 04, 2020, 09:55:56 PM »
Changing over to escaping with \" instead of """.  The documentation has been updated, and I've tested with command line and shortcut to verify it still works (didn't try with powershell, as you have already confirmed this).  No code change needed, (assuming) it works with all three ways.

I've also increased the performance a bit when using command line parameters against the already-running instance of VA.  Not sure if it solves what you are trying to do, but it seems a bit faster for me executing from, say, a .bat file (20 or more times in a row).

This will be in the next beta, however, if you want it now v1.8.6.6 is in the, 'unofficial' bin: http://voiceattack.com/u

If I find regression tests fail on this and it needs to be rolled back, we'll be back to square one (hoping that's not the case lol o_O)

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #21 on: August 10, 2020, 02:52:09 PM »
I've also increased the performance a bit when using command line parameters against the already-running instance of VA.  Not sure if it solves what you are trying to do, but it seems a bit faster for me executing from, say, a .bat file (20 or more times in a row).

Doing about 1/s works reliably now for me. Doing two basically at the same time still doesn’t, but I can probably work around that :)

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Passing variables via command line
« Reply #22 on: August 10, 2020, 08:39:50 PM »
Thanks for the feedback.  I'm finding that's about as fast as it's going to get with this implementation, unfortunately.  If you need to go faster, you'll want to consider writing a VA plugin that you can communicate with directly.

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #23 on: August 11, 2020, 03:46:52 AM »
Roger :)

But … remember this one?

Code: [Select]
8/11/2020 11:41:30 AM***************************************************************************************
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at VoiceAttack.frmMain..(KeyValuePair`2 )
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at VoiceAttack.frmMain.(Command2 , Command2 , Boolean )
   at VoiceAttack.frmMain.(Command2 , Process , Boolean , Boolean , Int32 , Boolean , Nullable`1 , Guid , Guid , List`1 , Command2 )
   at VoiceAttack.frmMain.–.()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()
***VoiceAttack v1.8.6.6 - Windows 10.0.18362.0

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Passing variables via command line
« Reply #24 on: August 11, 2020, 07:27:25 PM »
This is not the same stack trace as from the other thread.  Could you elaborate a bit on what it is you're doing?  Are you using any command-shared variables (variables named with ~~ at the beginning)?

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #25 on: August 14, 2020, 11:46:44 AM »
This is not the same stack trace as from the other thread.

Looked similar enough to me that I didn’t actually double-check, sorry :D

Could you elaborate a bit on what it is you're doing?

I … literally didn’t do anything. Was AFK, came back, VA had crashed. Hasn’t happened again since then, I’ll keep an eye out (and open a fresh report if it happens again).

Are you using any command-shared variables (variables named with ~~ at the beginning)?

Yeah, lots. Including in the IRC-driven externally invoked commands, probably was one of those.

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Passing variables via command line
« Reply #26 on: August 14, 2020, 12:34:12 PM »
There is an area where I’m wanting to try changing up.  Looks like this one is occurring with command-shared variables.  Probably have something in the next few days to try out.

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #27 on: August 15, 2020, 04:29:47 PM »
If you need to go faster, you'll want to consider writing a VA plugin that you can communicate with directly.

Since I’m starting to poke around in the docs and hacking away at getting familiar with the entire Plugins thing … can you clarify what I would have to do to alleviate the issue using a plugin?

I expect it’s not as easy as
  • call external command
  • hand parameters over to plugin
  • ? ? ?
  • profit
and that would still run into the same issue, right? :)

Gary

  • Administrator
  • Hero Member
  • *****
  • Posts: 2832
Re: Passing variables via command line
« Reply #28 on: August 15, 2020, 07:03:53 PM »
It should alleviate the speed problem (somewhat) - not the exception that you indicated recently.

What you're trying to do is pass data to VoiceAttack externally.  Since VA does not have a way to do this other than through the command line, you're at the mercy of Windows launching an app (VA) that either consumes the passed information from the command line (the launched instance) or relay the command line info to the already-running instance of VA.  Since this is not tested or intended as a data management platform, the onus would be on you to make that happen - the only way to do this reliably would be through a plugin.  Even with a plugin you'll probably hit other walls that are not accounted for, as VA is not designed for high-volume data interchange - if it receives and processes data at high rates of speed, great - however, it's not designed or intended to do that.

The idea would be that you would establish a plugin that would act as as the recipient of whatever data you need to feed it -  that would mean an additional external app to act as the sender (which I'm assuming you already have).

alterNERDtive

  • Jr. Member
  • **
  • Posts: 52
Re: Passing variables via command line
« Reply #29 on: August 17, 2020, 12:38:56 AM »
Yeah, that’s what I thought. TBF though just prying the string splitting/processing out of a command and putting it into actual code has already made the command itself a couple seconds faster. And no, I don’t have a sending application yet. I haven’t done .Net in … 13(?) years so I guess it’s a good reason to brush up on it.

The actual plugin part was less hassle than I feared it would be, though I guess I do have a somewhat decent understanding of how VoiceAttack works under the hood now so that is helpful.