start a (guest program) Office-file directly from the host

Discussions related to using VirtualBox on Linux hosts.
Post Reply
Plagrö
Posts: 140
Joined: 27. May 2018, 14:57

start a (guest program) Office-file directly from the host

Post by Plagrö »

When I type this command in a terminal ...

Code: Select all

VBoxManage --nologo guestcontrol "Win7" run --exe "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE" --username Plagrö --password 123456
... then Excel starts as expected. But my 4 cpu cores are permanently at 60%, although I do not make anything in Excel.

When I start Excel normal via menu in my guest, then my 4 cpu cores are < 5%.

Why this difference?
Is there a possibility to have also only 5%, when I start Excel directly in host?

Very interested in this. Would appreciate some help. Thank you.
Last edited by Plagrö on 16. Oct 2020, 23:10, edited 1 time in total.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: 60% cpu: start a guest program directly from the host

Post by scottgus1 »

There are no settings in Virtualbox to control this that I know of.

Try running other programs, like Notepad or Calculator. Also try running without the --nologo switch. Also make a new account in the guest with only ascii characters for the name, not with the umlaut or other accent marks.

See if any of these don't cause the high CPU.
Plagrö
Posts: 140
Joined: 27. May 2018, 14:57

Re: 60% cpu: start a guest program directly from the host

Post by Plagrö »

Thank you.

I have found out, how I must change the command, so that it uses <5% cpu.
Just replaced "run" through "start":

Code: Select all

[code]VBoxManage --nologo guestcontrol "Win7" start --exe "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE" --username Plagrö --password 123456
[/code]

But now I have a new problem, I had not before.

The whole command is actually:

Code: Select all

VBoxManage startvm "Win7" && VBoxManage --nologo guestcontrol "Winl" run --exe "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE" --username Plagrö --password 123456
This work, but with 60% cpu.

When I then replace "run" with "start":

Code: Select all

VBoxManage startvm "Win7" && VBoxManage --nologo guestcontrol "Winl" start --exe "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE" --username Plagrö --password 123456
Then the VM starts, but not Excel.

But I found this contribution from you:
viewtopic.php?f=2&t=99261&p=481531&hili ... ol#p481536

Here you suggest to use guestproperty in a loop.
I am not a programmer. I only have made once some programmer steps in my pocket PC with the programmer language "Basic". It looks like Bash is way more complicated with variables. (= == -eq (()) () [] [[]] STR $STR "$STR"). I have tried hard to find out how to do this. But I was just not successful.

I have tried this:

Code: Select all

#!/bin/bash
VBoxManage startvm "Win7" 
until [[  STR -eq 1  ]]
do
STR=VBoxManage guestproperty get "Win7" "/VirtualBox/GuestInfo/OS/LoggedInUsers"
sleep .01
done

VBoxManage --nologo guestcontrol "Win7" start --exe "C:\Program Files\Microsoft Office\Office14\EXCEL.EXE" --username Plagrö --password 123456
Output:

Code: Select all

Waiting for VM "Win7" to power on...
VM "Win7" has been successfully started.
/home/Plagrö/Desktop/Excel.sh: line 5: guestproperty: command not found.
---

STR=VBoxManage guestproperty get "Win7" "/VirtualBox/GuestInfo/OS/LoggedInUsers" works in a terminal without "STR=". But I need STR to make the test in "until". (?)

Thank you.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: 60% cpu: start a guest program directly from the host

Post by scottgus1 »

Good find on "start" vs. "run"! The manual says they do almost the same except "run" funnels the command-line output from the started program back to the host OS, which might account for the extra CPU. Maybe there's a loop in the Virtualbox code waiting for these outputs that is running amok?

I'm nowhere near being able to script in Bash, but I did do DOS batch files.

If the structure of the until/do/done loop is set up right, and the ability to put the output of 'vboxmanage guestproperty get' into the variable STR works, then the contents of STR and the test thereof, "STR -eq 1" might be the problem.

When 'vboxmanage guestproperty get' output is redirected into a text file, as in this from a DOS batch file:
vboxmanage guestproperty get <vmname> /vmcontrol/heartbeat > "heartbeat.txt"
the file "heartbeat.txt" contains the text, "value: <value>"

If STR also contains "value: <value>" it should never become equal to "1". Maybe "value: 1"?
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: 60% cpu: start a guest program directly from the host

Post by fth0 »

Try something like:

Code: Select all

while [ "$(VBoxManage ...)" == "1" ]; do sleep 1; done
Plagrö
Posts: 140
Joined: 27. May 2018, 14:57

Re: 60% cpu: start a guest program directly from the host

Post by Plagrö »

Thank you for the hint.

I have tried this out, but was not successful.

But in the meantime I have found this:
https://unix.stackexchange.com/question ... rough-virt

And I was successful with it. I have taken the solution below "several tweaks":

Code: Select all

#!/bin/bash
# Start VM (if it is already started this does nothing)
VBoxManage startvm "MyVM"



# Replace folders with windows-local versions (mounts need to be setup)
#/data/ is mounted as F:
original=$1
findWhat=\/home/user/public/
replaceWith="F:\\"
fixedFilePath="${original/$findWhat/$replaceWith}"

# /home/USER/ is mounted as G:
original=$fixedFilePath
findWhat=\/home/user/
replaceWith="G:\\"
fixedFilePath="${original/$findWhat/$replaceWith}"




options=(
    --username Plagrö 
    --password 123456
    --exe "%SystemRoot%\system32\cmd.exe"
    -- 'cmd' /c start "run this" "$fixedFilePath"
)



nError=1
nTries=0

while [ $nError -gt 0 ] && [ $nTries -lt 20 ]; do

echo $nTries

   nError=$(VBoxManage guestcontrol "MyVM" start "${options[@]}" 2>&1 >/dev/null | grep -c "error")
   ((++nTries))
   sleep 2


done
Last edited by Plagrö on 19. Oct 2020, 10:49, edited 1 time in total.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: start a (guest program) Office-file directly from the host

Post by fth0 »

Plagrö wrote:I have tried this out, but was not successful.
You did replace the "..." in my proposal, didn't you? ;)
Post Reply