Page 1 of 1

How to use the output of my first command in my second command in one step?

Posted: 13 Feb 2021 12:31
by Furplado
Hello all together,

(My system: Windows 7 Virtual Machine)

I have two commands.
The output of one command should be used for my other command.
-> But it does not work.

(cmd-window)

What is my first command inclusive output?
It is:

Code: Select all

C:\>REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice
    Progid    REG_SZ    Word.Document.12

What is my second command?

it is:

Code: Select all

C:\>D:\NT3x\vboxcontrol guestproperty set /myproperties/myproperty "MyText"
Oracle VM VirtualBox Guest Additions Command Line Management Interface Version 6.1.14
(C) 2008-2020 Oracle Corporation
All rights reserved.
This is the check, if the second command has really worked:

Code: Select all

C:\>D:\NT3x\vboxcontrol guestproperty get /myproperties/myproperty
Oracle VM VirtualBox Guest Additions Command Line Management Interface Version 6.1.14
(C) 2008-2020 Oracle Corporation
All rights reserved.

Value: MyText
-> Yes the check is positive. It has worked. "MyText" is in the "myproperty".


I want, that the output of my first command is used as a replacement for "MyText" in my second command (... and so is saved in the property "myproperty").

Important:
It should be a direct way (in one step/in one line). Not create a first command line for putting the output into a variable and then create a second command line to put the content of this variable in my "myproperty".


Until now I have tried this variants. But all failed:

Code: Select all

C:\>D:\NT3x\vboxcontrol guestproperty set /myproperties/myproperty REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersionExplorer\FileExts\.docx\UserChoiceoice

Code: Select all

C:\>D:\NT3x\vboxcontrol guestproperty set /myproperties/myproperty %REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersionExplorer\FileExts\.docx\UserChoiceoice%

Code: Select all

C:\>D:\NT3x\vboxcontrol guestproperty set /myproperties/myproperty echo REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersionExplorer\FileExts\.docx\UserChoiceoice

Code: Select all

C:\>D:\NT3x\REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersionExplorer\FileExts\.docx\UserChoiceoice | vboxcontrol guestproperty set /myproperties/myproperty


Question: How can I bring the output of "REG QUERY HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice" into my "myproperty" ?



Would appreciate some help. Thank you.

Re: How to use the output of my first command in my second command in one step?

Posted: 14 Feb 2021 04:39
by siberia-man
Create a batch script with this content:

Code: Select all

@echo off

setlocal

set "reg_key=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice"

for /f "tokens=1,2,3" %%a in ( '
	reg query "%reg_key%"
' ) do if /i "%%~a" == "Progid" (
	vboxcontrol guestproperty set /myproperties/myproperty "%%~c"
)

vboxcontrol guestproperty set /myproperties/myproperty
It fairly should fit your request. Honestly batch script language is ugly.

Re: How to use the output of my first command in my second command in one step?

Posted: 15 Feb 2021 07:55
by jfl
This can be done easily using helper scripts:
regx.bat makes it easy to get the content of a registry value. It works as if the registry were a filesystem, with keys as directories, and values as files:

Code: Select all

regx type HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice\Progid
Then $.bat allows capturing the output of a command into a variable, for easy reuse in the next command.
For example, this sets variable Progid with the output of the above command, then reuses it in your second command :

Code: Select all

$ Progid regx type HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice\Progid
D:\NT3x\vboxcontrol guestproperty set /myproperties/myproperty "%Progid%"
Both scripts have a -? option displaying a help screen.

Re: How to use the output of my first command in my second command in one step?

Posted: 15 Feb 2021 09:37
by Furplado
Sorry for the delay and thank you both.

It's done.

Re: How to use the output of my first command in my second command in one step?

Posted: 15 Feb 2021 20:30
by Compo
This would be my suggested single line command, from cmd.exe, i.e. no need for a batch file.

Code: Select all

For /F "EOL=H Tokens=2,*" %G In ('""%SystemRoot%\System32\reg.exe" Query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.docx\UserChoice" /V "ProgId" 2> NUL"') Do @"D:\NT3x\VBoxControl.exe" --nologo guestproperty set /myproperties/myproperty "%H"

Re: How to use the output of my first command in my second command in one step?

Posted: 21 Feb 2021 02:47
by Furplado
Wow, thank you @Compo. Exactly what I was asking for.