summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorunknown <jani@hynda.mysql.fi>2001-11-06 23:00:03 +0200
committerunknown <jani@hynda.mysql.fi>2001-11-06 23:00:03 +0200
commite49cf66e07b2b3abdceb63beed09ea9045c2dbb8 (patch)
treef468bc952d01b72275a0cf7a2017a8ce081b014b /client
parentcaf8bee731f85ce6cf0fc3b96b4514b9eee15943 (diff)
downloadmariadb-git-e49cf66e07b2b3abdceb63beed09ea9045c2dbb8.tar.gz
Added internal command \! to mysql client which can be used
to execute system commands within the client in UNIX. client/mysql.cc: Added option to run shell commands from the mysql client (\!)
Diffstat (limited to 'client')
-rw-r--r--client/mysql.cc30
1 files changed, 28 insertions, 2 deletions
diff --git a/client/mysql.cc b/client/mysql.cc
index 19e95b2f1c8..d62e3bfe3cf 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -38,7 +38,7 @@
#include <signal.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 */
#define MAX_COLUMN_LENGTH 1024
@@ -159,7 +159,7 @@ static int com_quit(String *str,char*),
com_connect(String *str,char*), com_status(String *str,char*),
com_use(String *str,char*), com_source(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__
static int com_nopager(String *str, char*), com_pager(String *str, char*),
@@ -217,6 +217,9 @@ static COMMANDS commands[] = {
{ "source", '.', com_source, 1,
"Execute a SQL script file. Takes a file name as an argument."},
{ "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,
"Set outfile [to_outfile]. Append everything into given outfile." },
{ "use", 'u', com_use, 1,
@@ -2053,6 +2056,29 @@ com_rehash(String *buffer __attribute__((unused)),
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
com_print(String *buffer,char *line __attribute__((unused)))
{