how to get the output from vboxmanage list runningvms in PHP or Python

Discussions related to using VirtualBox on Windows hosts.
Post Reply
Gilmo
Posts: 2
Joined: 25. Mar 2022, 17:13

how to get the output from vboxmanage list runningvms in PHP or Python

Post by Gilmo »

When I call "vboxmanage list runningvms" I can't capture the output in PHP and echo the text.

I tried piping, redirecting, etc. and no luck.

Here is the code:

Code: Select all

    $output2=null;
    $retvar=null;
    echo "<h3>Check for running VMs</h3>";
    $output2 = shell_exec("vboxmanage.exe list runningvms");
    echo "<pre>$output2</pre>";
it returns nothing.

I also tried:

a.

Code: Select all

    $output2 = shell_exec("vboxmanage.exe list runningvms>runningvms.txt");
but the txt file is empty

b.

Code: Select all

        $output2 = shell_exec("vboxmanage.exe list runningvms 2>&1");
it returns nothing

c.
Calling the version works

Code: Select all

    $output2 = shell_exec("vboxmanage.exe --version");
I get vbox version 6.0.24r139119 which is my test VM.

I don't know if this is STDOUT but I can't think of another way to capture the output of "list runningvms"

This is running on a Windows 7 with IIS 7. I cannot use Linux, I cannot use Apache and I cannot upgrade to Windows 10. If you find out that it works in other OSs it will make me jealous but it does not solve my problem so please focus on Windows 7 with IIS 7.

Let me know if there is another way to do this programmaticaly and send it to PHP. I could call Python and send to a text and read the text file in PHP. I will try this unless anyone here has a better way.

Thanks,
Gilmo
Posts: 2
Joined: 25. Mar 2022, 17:13

Re: how to get the output from vboxmanage list runningvms in PHP or Python

Post by Gilmo »

I think that it is an issue with the way vboxmanage calls "list" because from the command line when I call "vboxmanage list runningvms" it works but when I call it using

Code: Select all

"runas /user:devops "cmd /k vboxmanage list runningvms" 
I get nothing also. in this case the user devops is also admin level user.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows, Linux

Re: how to get the output from vboxmanage list runningvms in PHP or Python

Post by scottgus1 »

Gilmo wrote:Calling the version works
   

Code: Select all

 $output2 = shell_exec("vboxmanage.exe --version");
I get vbox version 6.0.24r139119 which is my test VM.
I don't know how to guide you further, but I am highlighting this part to any forum gurus who may come along, as I had thought to finger 'shell_exec' et al, and the above indicates that shell_exec can feed some vboxmanage outputs into the variable.
Post Reply