Unable to run script in Ubuntu guest

Discussion about using the VirtualBox API, Tutorials, Samples.

Unable to run script in Ubuntu guest

Postby LordKaoS » 8. Nov 2018, 21:27

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   Expand viewCollapse view
#!/bin/sh
# Contents of first.sh
touch test.txt

However, it fails at
Code: Select all   Expand viewCollapse view
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 23 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 23 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

Postby LordKaoS » 12. Nov 2018, 16:33

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).
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

Postby noteirak » 14. Nov 2018, 04:37

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://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: Unable to run script in Ubuntu guest

Postby LordKaoS » 14. Nov 2018, 13:09

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.
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

Postby noteirak » 14. Nov 2018, 20:23

The one labeled "Run Guest Process and Read Stdout" is what you are after.
Hyperbox - Virtual Infrastructure Manager - https://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7


Return to The VirtualBox API

Who is online

Users browsing this forum: No registered users and 1 guest