0

I want to open a vm through following php code:

<?php
$output = shell_exec("virt-viewer --connect qemu:///system 1 2>&1");
echo "<pre>$output</pre>";
?>

I already set the permission of a file with read,write and execute.

I am getting the following error:

(virt-viewer:15162): Gtk-WARNING **: 22:45:33.686: cannot open display:

please help if i am missing something or doing something wrong. Thanks

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

1 Answers1

0

How web page works:

Browser makes request to web server, web server delivers html and optionally other asset files (css, js..), but generally, html is loaded first and it stays as it is - content is not changed (except if it's changed by JS, which is not the case here).

Your call will execute some shell command it will return some response (some text) and you'll get it inside some var. If you display that static text as part of your page how do you expect that it will act as GUI?!?

That's just not possible. Imaging that you are calling from shell_exec() exe file of some video game? Will the game then run in the browser?!?

You can call shell commands in order to trigger some action on server (i.e. rescale some image, process some video) or to collect some response (i.e. free disk space or something). But expecting that if you call something form shell will appear in browser is just not realistic.

MilanG
  • 6,994
  • 2
  • 35
  • 64
  • I will make it simple! I am just trying to use this command to open a virtual machine inside a browser and i used the word 'emulator' as an example just. – Kumari Saloni Aug 30 '19 at 11:25
  • @KumariSaloni — MilianG understands what you want to do. They are just telling you that it isn't possible. – Quentin Aug 30 '19 at 11:34
  • Yes, browser is not some kind of window which will pass anything you run in console. Browser delivers html as the main file. Don't know what you expect to collect from shell command and to pass as part of html that will act as a gui? Can you imagine source of your page that is running gui inside web page? It's important to understand how browser - web server relation works. – MilanG Aug 30 '19 at 13:17
  • @KumariSaloni when you look at page source what you expect to see between
     and 
    tags that will run console?
    – MilanG Aug 30 '19 at 13:52