It is currently October 18th, 2019, 12:10 pm

InputText cli

Help with creating, editing & fixing problems with skins
User avatar
UziTech
Posts: 5
Joined: April 24th, 2019, 1:39 pm

InputText cli

UziTech » April 24th, 2019, 1:48 pm

I am trying to create a skin that has an InputText that will be a command sent to cmd.exe or powershell.exe. I can get it to open the command prompt but not enter the command that was entered into the InputText.

Code: Select all

[measureCmd]
Measure=Plugin
Plugin=InputText
SolidColor=20,20,20,255
StringAlign=Left
StringCase=None
StringStyle=Bold
StringEffect=Shadow
FontEffectColor=0,0,0,20
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
X=10
Y=58
W=188
H=17
FocusDismiss=1
DefaultValue=""
Command1=["cmd" "$UserInput$"]
UpdateDivider=86400
What am I doing wrong?
User avatar
jsmorley
Developer
Posts: 19579
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: InputText cli

jsmorley » April 24th, 2019, 2:02 pm

You can't just pass a command to cmd.exe that way.

Try:
Command1=[cmd.exe /C "$UserInput$"]

You can use cmd /? to get help with cmd.exe while in a console.

Code: Select all

C:\Users\Jeffrey>cmd /?
Starts a new instance of the Windows command interpreter

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
    [[/S] [/C | /K] string]

/C      Carries out the command specified by string and then terminates
/K      Carries out the command specified by string but remains
/S      Modifies the treatment of string after /C or /K (see below)
/Q      Turns echo off
/D      Disable execution of AutoRun commands from registry (see below)
/A      Causes the output of internal commands to a pipe or file to be ANSI
/U      Causes the output of internal commands to a pipe or file to be
        Unicode
/T:fg   Sets the foreground/background colors (see COLOR /? for more info)
/E:ON   Enable command extensions (see below)
/E:OFF  Disable command extensions (see below)
/F:ON   Enable file and directory name completion characters (see below)
/F:OFF  Disable file and directory name completion characters (see below)
/V:ON   Enable delayed environment variable expansion using ! as the
        delimiter. For example, /V:ON would allow !var! to expand the
        variable var at execution time.  The var syntax expands variables
        at input time, which is quite a different thing when inside of a FOR
        loop.
/V:OFF  Disable delayed environment expansion.
User avatar
UziTech
Posts: 5
Joined: April 24th, 2019, 1:39 pm

Re: InputText cli

UziTech » April 24th, 2019, 2:29 pm

Thanks, that worked. I updated my command to:

Code: Select all

Command1=[cmd /K cd %USERPROFILE% && $UserInput$]
So it will execute any commands in the user folder and leave the command prompt open.
User avatar
jsmorley
Developer
Posts: 19579
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: InputText cli

jsmorley » April 24th, 2019, 2:31 pm

Glad to help.
User avatar
UziTech
Posts: 5
Joined: April 24th, 2019, 1:39 pm

Re: InputText cli

UziTech » April 24th, 2019, 2:38 pm

I was able to get powershell working with:

Code: Select all

Command1=[powershell -NoExit -Command cd $Env:USERPROFILE; $UserInput$]
User avatar
jsmorley
Developer
Posts: 19579
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: InputText cli

jsmorley » April 24th, 2019, 2:45 pm

To make this more reliable on different computers, I'd be tempted to use:

Command1=[powershell -NoProfile -ExecutionPolicy Bypass -NoExit -Command cd $Env:USERPROFILE; $UserInput$]
User avatar
UziTech
Posts: 5
Joined: April 24th, 2019, 1:39 pm

Re: InputText cli

UziTech » April 24th, 2019, 3:09 pm

In my case I want my profile scripts to run. I essentially want this to be the same as opening powershell and running a command just faster since I don't have to open powershell first.
User avatar
jsmorley
Developer
Posts: 19579
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: InputText cli

jsmorley » April 24th, 2019, 3:11 pm

UziTech wrote:
April 24th, 2019, 3:09 pm
In my case I want my profile scripts to run. I essentially want this to be the same as opening powershell and running a command just faster since I don't have to open powershell first.
Fair enough. I just suggested those parms as by default powerhshell is not enabled from the command line in Windows, as a security measure. If this is on your computer only, and you have powershell configured to execute the way you want, then they are certainly not needed.
User avatar
UziTech
Posts: 5
Joined: April 24th, 2019, 1:39 pm

Re: InputText cli

UziTech » May 9th, 2019, 3:53 pm

In case anyone want's to use WSL:

Code: Select all

Command1=[bash -c 'cd ~;$UserInput$;bash']