}
}
- // Capture and return the output?
- if (return_output) {
- // Allocate a new buffer
- output = PyBytes_FromString("");
- if (!output)
- goto ERROR;
-
- // Register a function that captures the output
- stdout_callback = Pakfire_execute_stdout_callback;
- }
+ // Allocate a new output buffer
+ output = PyBytes_FromString("");
+ if (!output)
+ goto ERROR;
// Create a new jail
r = pakfire_jail_create(&jail, self->pakfire);
Py_BEGIN_ALLOW_THREADS
// Execute command
- r = pakfire_jail_communicate(jail, argv, env, 0, NULL, NULL, stdout_callback, &output);
+ r = pakfire_jail_communicate(jail, argv, env, 0,
+ NULL, NULL, Pakfire_execute_stdout_callback, &output);
Py_END_ALLOW_THREADS
// Otherwise the executed command returned some error code
} else if (r > 0) {
- PyObject* code = PyLong_FromLong(r);
+ PyObject* error = Py_BuildValue("iO", r, output);
+ if (!error)
+ goto ERROR;
// Raise CommandExecutionError
- PyErr_SetObject(PyExc_CommandExecutionError, code);
- Py_DECREF(code);
+ PyErr_SetObject(PyExc_CommandExecutionError, error);
+ Py_DECREF(error);
goto ERROR;
}
self.pakfire.execute(["/command", "exit-with-code", "123"])
# Extract return code
- code, = e.exception.args
+ code, output = e.exception.args
self.assertTrue(code == 123)
+ self.assertIsInstance(output, bytes)
def test_environ(self):
r = self.pakfire.execute(["/command", "echo-environ", "VAR1"],