summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-08-14 17:28:25 +0200
committerDave Davenport <qball@gmpclient.org>2017-08-14 17:28:25 +0200
commit8a99f0b7bd89c37c844af3307ff22d92cb584802 (patch)
treebf8d8e00181241e350e0fd5810d67dd09d082b4b
parent004cc70ff606e363d72e7dc897931334e4d9c7a7 (diff)
[Script] Execute script + argument direction, do not pass run-command.
Fixes: #650
-rw-r--r--source/dialogs/script.c28
-rw-r--r--source/helper.c2
2 files changed, 18 insertions, 12 deletions
diff --git a/source/dialogs/script.c b/source/dialogs/script.c
index a4daf289..8718b382 100644
--- a/source/dialogs/script.c
+++ b/source/dialogs/script.c
@@ -41,12 +41,24 @@
#include "helper.h"
#include "mode-private.h"
-static char **get_script_output ( const char *command, unsigned int *length )
+static char **get_script_output ( char *command, char *arg, unsigned int *length )
{
+ int fd = -1;
+ GError *error = NULL;
char **retv = NULL;
-
+ char *args[3] = { command, arg, NULL };
*length = 0;
- int fd = execute_generator ( command );
+
+ g_spawn_async_with_pipes ( NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &fd, NULL, &error );
+
+ if ( error != NULL ) {
+ char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", command, error->message );
+ rofi_view_error_dialog ( msg, FALSE );
+ g_free ( msg );
+ // print error.
+ g_error_free ( error );
+ fd = -1;
+ }
if ( fd >= 0 ) {
FILE *inp = fdopen ( fd, "r" );
if ( inp ) {
@@ -76,13 +88,9 @@ static char **get_script_output ( const char *command, unsigned int *length )
return retv;
}
-static char **execute_executor ( Mode *sw, const char *result, unsigned int *length )
+static char **execute_executor ( Mode *sw, char *result, unsigned int *length )
{
- char *arg = g_shell_quote ( result );
- char *command = g_strdup_printf ( "%s %s", (const char *) sw->ed, arg );
- char **retv = get_script_output ( command, length );
- g_free ( command );
- g_free ( arg );
+ char **retv = get_script_output ( sw->ed, result, length );
return retv;
}
@@ -108,7 +116,7 @@ static int script_mode_init ( Mode *sw )
if ( sw->private_data == NULL ) {
ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
sw->private_data = (void *) pd;
- pd->cmd_list = get_script_output ( (const char *) sw->ed, &( pd->cmd_list_length ) );
+ pd->cmd_list = get_script_output ( (char *) sw->ed, NULL, &( pd->cmd_list_length ) );
}
return TRUE;
}
diff --git a/source/helper.c b/source/helper.c
index b6af5b87..e8c74e34 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -484,8 +484,6 @@ int execute_generator ( const char * cmd )
if ( error != NULL ) {
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, error->message );
- fputs ( msg, stderr );
- fputs ( "\n", stderr );
rofi_view_error_dialog ( msg, FALSE );
g_free ( msg );
// print error.