Page 1 of 1

Unable to run script in Ubuntu guest

Posted: 8. Nov 2018, 21:27
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 61 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 61 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)

Re: Unable to run script in Ubuntu guest

Posted: 12. Nov 2018, 16:33
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).

Re: Unable to run script in Ubuntu guest

Posted: 14. Nov 2018, 04:37
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.

Re: Unable to run script in Ubuntu guest

Posted: 14. Nov 2018, 13:09
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.

Re: Unable to run script in Ubuntu guest

Posted: 14. Nov 2018, 20:23
by noteirak
The one labeled "Run Guest Process and Read Stdout" is what you are after.