Unable to run script in Ubuntu guest

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
LordKaoS
Posts: 11
Joined: 29. Oct 2018, 09:04
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Ubuntu 18.04, MS Windows 7

Unable to run script in Ubuntu guest

Post by LordKaoS »

Host: Windows 10 (64)
Guest: Ubuntu 18.04 (64)
Version: 5.2.20
Guest Additions: 5.2.20

Using python, I'm trying to execute a bash script in my Ubuntu guest

Code: Select all

#!/bin/sh
# Contents of first.sh
touch test.txt
However, it fails at

Code: Select all

changePermission = runner.processCreate("/bin/chmod", ["+x", DEST_PATH], None, [virtualBoxManager.constants.ProcessCreateFlag_WaitForProcessStartOnly], 0)
changePermission.waitFor(virtualBoxManager.constants.ProcessWaitForFlag_Terminate, 0)
print("Permissions changed")
realExec = runner.processCreate(DEST_PATH, None, None, [virtualBoxManager.constants.ProcessCreateFlag_WaitForProcessStartOnly], 0)
realExec.waitFor(virtualBoxManager.constants.ProcessWaitForFlag_Terminate, 0)
While it does print Permissions changed, the permissions do not actually change for the file, and thus raises
(-2147352567, 'Exception occurred.', (0, 'GuestProcessWrap', 'VERR_ACCESS_DENIED', None, 0, -2135228411), None)
I manually changed the permissions of the file, and ran
VBinit.txt
My code
(3.12 KiB) Downloaded 56 times
again after commenting out lines 40-43. This time, no exceptions occurred and the code exit cleanly, however, the script did not get executed either, as evident from the absence of test.txt.

Also, and I think this is a bug, I had to comment out lines 53-56 from
VBinit.txt
My code
(3.12 KiB) Downloaded 56 times
because fileExists() does not return False (as it should) if the file does not exist, and instead raises
(-2147352567, 'Exception occurred.', (0, 'GuestSessionWrap', 'No such file or directory on guest', None, 0, -2135228411), None)
LordKaoS
Posts: 11
Joined: 29. Oct 2018, 09:04
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Ubuntu 18.04, MS Windows 7

Re: Unable to run script in Ubuntu guest

Post by LordKaoS »

Update: The same programs works for Ubuntu host and Windows guest, though with some platform changes (replace shell script with batch script, commenting out permission management lines 44-48).
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Unable to run script in Ubuntu guest

Post by noteirak »

Terminate for the process flag may or may not work, depending on the host & guest. Also, you do not check for guest additions capabilities and will most likely trigger failures as the timing might not be right.
See the code sample for the high-level steps. Adapt to your version.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
LordKaoS
Posts: 11
Joined: 29. Oct 2018, 09:04
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Ubuntu 18.04, MS Windows 7

Re: Unable to run script in Ubuntu guest

Post by LordKaoS »

noteirak wrote:you do not check for guest additions capabilities and will most likely trigger failures as the timing might not be right.
I checked for AdditionsRunLevelType_Userland. Is that not enough? If so, please point me to the right sample, as there are many on that link, and I'm just starting out on this.
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Unable to run script in Ubuntu guest

Post by noteirak »

The one labeled "Run Guest Process and Read Stdout" is what you are after.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply