Commit 20e01ba3 authored by jani@hynda.mysql.fi's avatar jani@hynda.mysql.fi

Added internal command \! to mysql client which can be used

to execute system commands within the client in UNIX.
parent 1dd8fd59
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
#include <signal.h> #include <signal.h>
#include <violite.h> #include <violite.h>
const char *VER="11.17"; const char *VER="11.18";
/* Don't try to make a nice table if the data is too big */ /* Don't try to make a nice table if the data is too big */
#define MAX_COLUMN_LENGTH 1024 #define MAX_COLUMN_LENGTH 1024
...@@ -159,7 +159,7 @@ static int com_quit(String *str,char*), ...@@ -159,7 +159,7 @@ static int com_quit(String *str,char*),
com_connect(String *str,char*), com_status(String *str,char*), com_connect(String *str,char*), com_status(String *str,char*),
com_use(String *str,char*), com_source(String *str, char*), com_use(String *str,char*), com_source(String *str, char*),
com_rehash(String *str, char*), com_tee(String *str, char*), com_rehash(String *str, char*), com_tee(String *str, char*),
com_notee(String *str, char*); com_notee(String *str, char*), com_shell(String *str, char *);
#ifndef __WIN__ #ifndef __WIN__
static int com_nopager(String *str, char*), com_pager(String *str, char*), static int com_nopager(String *str, char*), com_pager(String *str, char*),
...@@ -217,6 +217,9 @@ static COMMANDS commands[] = { ...@@ -217,6 +217,9 @@ static COMMANDS commands[] = {
{ "source", '.', com_source, 1, { "source", '.', com_source, 1,
"Execute a SQL script file. Takes a file name as an argument."}, "Execute a SQL script file. Takes a file name as an argument."},
{ "status", 's', com_status, 0, "Get status information from the server."}, { "status", 's', com_status, 0, "Get status information from the server."},
#ifndef __WIN__
{ "system", '!', com_shell, 1, "Execute a system shell command."},
#endif
{ "tee", 'T', com_tee, 1, { "tee", 'T', com_tee, 1,
"Set outfile [to_outfile]. Append everything into given outfile." }, "Set outfile [to_outfile]. Append everything into given outfile." },
{ "use", 'u', com_use, 1, { "use", 'u', com_use, 1,
...@@ -2053,6 +2056,29 @@ com_rehash(String *buffer __attribute__((unused)), ...@@ -2053,6 +2056,29 @@ com_rehash(String *buffer __attribute__((unused)),
return 0; return 0;
} }
#ifndef __WIN__
static int
com_shell(String *buffer, char *line __attribute__((unused)))
{
char *shell_cmd;
if (!(shell_cmd = strchr(line, ' ')))
{
put_info("Usage: \\! shell-command", INFO_ERROR);
return -1;
}
/* The output of the shell command does not
get directed to the pager or the outfile */
if(system(shell_cmd) == -1)
{
put_info(strerror(errno), INFO_ERROR, errno);
return -1;
}
return 0;
}
#endif
static int static int
com_print(String *buffer,char *line __attribute__((unused))) com_print(String *buffer,char *line __attribute__((unused)))
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment