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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Furplado
Posts: 12
Joined: 13 Feb 2021 10:18

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

#1 Post by Furplado » 13 Feb 2021 12:31

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.

siberia-man
Posts: 174
Joined: 26 Dec 2013 09:28
Contact:

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

#2 Post by siberia-man » 14 Feb 2021 04:39

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.

jfl
Posts: 176
Joined: 26 Oct 2012 06:40
Location: Saint Hilaire du Touvet, France
Contact:

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

#3 Post by jfl » 15 Feb 2021 07:55

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.

Furplado
Posts: 12
Joined: 13 Feb 2021 10:18

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

#4 Post by Furplado » 15 Feb 2021 09:37

Sorry for the delay and thank you both.

It's done.

Compo
Posts: 538
Joined: 21 Mar 2014 08:50

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

#5 Post by Compo » 15 Feb 2021 20:30

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"

Furplado
Posts: 12
Joined: 13 Feb 2021 10:18

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

#6 Post by Furplado » 21 Feb 2021 02:47

Wow, thank you @Compo. Exactly what I was asking for.

Post Reply