How to catch error message given by a command

Discussions about using Linux guests in VirtualBox.
Post Reply
jcdole
Posts: 95
Joined: 3. May 2013, 18:25
Primary OS: openSUSE
VBox Version: PUEL
Guest OSses: WIN 7, WIN 10
Location: South west of france

How to catch error message given by a command

Post by jcdole »

hello.
This command give a screen error message :

Code: Select all

~> VBoxManage showvminfo "UUID_REPAIR_B"
VBoxManage: error: Could not find a registered machine named 'UUID_REPAIR_B'
VBoxManage: error: Details: code VBOX_E_OBJECT_NOT_FOUND (0x80bb0001), component VirtualBoxWrap, interface IVirtualBox, callee nsISupports
VBoxManage: error: Context: "FindMachine(Bstr(VMNameOrUuid).raw(), machine.asOutParam())" at line 2733 of file VBoxManageInfo.cpp
The error code return by "$?" is 1 , that mean an error occur.

Is it possible to redirect the output to a temporary file like this :

Code: Select all

VBoxManage showvminfo "UUID_REPAIR_B" > /tmp/some_error.txt
I got the file '/tmp/some_error.txt' but it is empty.

Any help is welcome.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to catch error message given by a command

Post by mpack »

Puzzling.

The answer will depend on the OS.

But - you posted in "Linux Guests". Are you asking how to type a command at a Linux guest terminal prompt? You can't access the host VirtualBox software at a guest terminal.
fth0
Volunteer
Posts: 5677
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: How to catch error message given by a command

Post by fth0 »

In bash (and many other shells), use

Code: Select all

VBoxManage showvminfo "UUID_REPAIR_B" > /tmp/some_error.txt 2>&1
which redirects both stdout and stderr to the file. Note that the order of the redirections is important and correct that way, although being counter-intuitive. Google "2>&1" if you want to learn more about it.
jcdole
Posts: 95
Joined: 3. May 2013, 18:25
Primary OS: openSUSE
VBox Version: PUEL
Guest OSses: WIN 7, WIN 10
Location: South west of france

Re: How to catch error message given by a command

Post by jcdole »

Great.
Thank you very much
Post Reply