1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) XXXX-2008 - INRIA
3 // Copyright (C) XXXX-2008 - INRIA - Allan CORNET
5 // Copyright (C) 2012 - 2016 - Scilab Enterprises
7 // This file is hereby licensed under the terms of the GNU GPL v2.0,
8 // pursuant to article 5.3.4 of the CeCILL v.2.1.
9 // This file was originally licensed under the terms of the CeCILL v2.1,
10 // and continues to be available under such terms.
11 // For more information, see the COPYING file which you should have received
12 // along with this program.
16 //unix_w - shell command execution results redirected in main scilab window
20 // cmd - a character string
22 // cmd instruction (sh syntax) is passed to shell, the standard output
23 // is redirected to main scilab window
27 // host unix_x unix_s unix_g
33 error(msprintf(gettext("%s: Wrong number of input argument(s): %d expected.\n"),"unix_w",1));
36 if type(cmd) <> 10 then
37 error(msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"unix_w",1));
40 if size(cmd,"*") <> 1 then
41 error(msprintf(gettext("%s: Wrong size for input argument #%d: string expected.\n"),"unix_w",1));
44 if getos() == "Windows" then
45 [rep,stat]=dos(cmd,"-echo");
47 error(msprintf(gettext("%s: error during ""%s"" execution"),"unix_w",cmd));
50 tmp=TMPDIR+"/unix.out";
51 cmd1="("+cmd+")>"+ tmp +" 2>"+TMPDIR+"/unix.err;";
56 write(%io(2),read(tmp,-1,1,"(a)"));
57 case -1 then // host failed
58 error(msprintf(gettext("%s: The system interpreter does not answer..."),"unix_w"));
60 msg=read(TMPDIR+"/unix.err",-1,1,"(a)");
61 if (size(msg,"*") == 0) then // If the program does not return anything
64 errmsg = msprintf(gettext("%s: The command failed with the error code ""%s"" and the following message:\n"),"unix_w",string(stat));
65 error(msprintf("%s\n"+strcat(msg, "\n"), errmsg));