Merge lp:~zorba-coders/zorba/process-2 into lp:zorba/process-module

Proposed by Nicolae Brinza
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/process-2
Merge into: lp:zorba/process-module
Diff against target: 582 lines (+274/-57)
17 files modified
src/com/zorba-xquery/www/modules/CMakeLists.txt (+1/-1)
src/com/zorba-xquery/www/modules/process.xq (+107/-11)
src/com/zorba-xquery/www/modules/process.xq.src/process.cpp (+115/-33)
src/com/zorba-xquery/www/modules/process.xq.src/process.h (+7/-4)
test/ExpQueryResults/process2-01.xml.res (+1/-0)
test/ExpQueryResults/process2-02.xml.res (+1/-0)
test/ExpQueryResults/process2-03.xml.res (+1/-0)
test/ExpQueryResults/process2-04.xml.res (+1/-0)
test/ExpQueryResults/process2-05.xml.res (+1/-0)
test/ExpQueryResults/process2-06.xml.res (+1/-0)
test/Queries/process.xq (+8/-8)
test/Queries/process2-01.xq (+5/-0)
test/Queries/process2-02.xq (+5/-0)
test/Queries/process2-03.xq (+5/-0)
test/Queries/process2-04.xq (+6/-0)
test/Queries/process2-05.xq (+5/-0)
test/Queries/process2-06.xq (+4/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/process-2
Reviewer Review Type Date Requested Status
Nicolae Brinza Approve
Matthias Brantner Pending
Review via email: mp+164354@code.launchpad.net

Commit message

Version 2.0 of the process module, allows running executables directly, without invoking bash/cmd.exe

Description of the change

Version 2.0 of the process module, allows running executables directly, without invoking bash/cmd.exe

To post a comment you must log in.
Revision history for this message
Nicolae Brinza (nbrinza) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/process-2 into lp:zorba/process-module failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job process-2-2013-05-17T12-29-40.913Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/process-2 into lp:zorba/process-module failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job process-2-2013-05-17T13-03-41.447Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/process-2 into lp:zorba/process-module failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job process-2-2013-05-17T13-34-44.754Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/process-2 into lp:zorba/process-module failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job process-2-2013-05-17T13-53-40.588Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/process-2 into lp:zorba/process-module failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job process-2-2013-05-17T14-27-39.824Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Nicolae Brinza (nbrinza) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/process-2 into lp:zorba/process-module failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job process-2-2013-05-17T14-42-40.749Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

lp:~zorba-coders/zorba/process-2 updated
40. By Nicolae Brinza

Fixed the build

41. By Nicolae Brinza

Updated documentation

42. By Nicolae Brinza

Addressed review comments: documentation fixes; brought back version 1.0 of the module, both 1.0 and 2.0 are avialable now

43. By Nicolae Brinza

Removed unused function

44. By Nicolae Brinza

The child fork()'ed process will now call abort() instead of exit() in order to avoid static object deallocation

45. By Nicolae Brinza

Improved comments; changed process module version from XQuery to JSONiq; removed xs: prefixes

46. By Nicolae Brinza

Moved the ver2.0 process module to the zorba.io ver1.0 namespace

47. By Matthias Brantner

moved files

48. By Matthias Brantner

fixed module naming and versioning

49. By Matthias Brantner

improve documentation

50. By Nicolae Brinza

Removed unecessary includes

51. By Nicolae Brinza

Changed module's errors to the new modules guidelines; Potential fix for execvpe() on Macs

52. By Nicolae Brinza

Merged with process module trunk

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/com/zorba-xquery/www/modules/CMakeLists.txt'
--- src/com/zorba-xquery/www/modules/CMakeLists.txt 2011-07-01 09:24:09 +0000
+++ src/com/zorba-xquery/www/modules/CMakeLists.txt 2013-05-17 14:51:23 +0000
@@ -12,4 +12,4 @@
12# See the License for the specific language governing permissions and12# See the License for the specific language governing permissions and
13# limitations under the License.13# limitations under the License.
1414
15DECLARE_ZORBA_MODULE (URI "http://www.zorba-xquery.com/modules/process" VERSION 1.0 FILE "process.xq")15DECLARE_ZORBA_MODULE (URI "http://www.zorba-xquery.com/modules/process" VERSION 2.0 FILE "process.xq")
1616
=== modified file 'src/com/zorba-xquery/www/modules/process.xq'
--- src/com/zorba-xquery/www/modules/process.xq 2012-12-06 02:13:28 +0000
+++ src/com/zorba-xquery/www/modules/process.xq 2013-05-17 14:51:23 +0000
@@ -28,14 +28,17 @@
28 :28 :
29 : Potential result:29 : Potential result:
30 : <pre class="ace-static" ace-mode="xquery"><![CDATA[30 : <pre class="ace-static" ace-mode="xquery"><![CDATA[
31 : <result xmlns="http://www.zorba-xquery.com/modules/process">31 : {
32 : <stdout>myfile.txt</stout>32 : "exit-code": 0,
33 : <stderr/>33 : "stdout": "myfile.txt",
34 : <exit-code>0</exit-code>34 : "stderr": ""
35 : </result>35 : }
36 : ]]></pre>36 : ]]></pre>
37 :37 :
38 : @author Cezar Andrei38 : The exec-command() set of functions allows execution of commands through the operating
39 : system's command line interpreter, such as "sh" on Linux or "cmd.exe" on Windows.
40 :
41 : @author Cezar Andrei, Nicolae Brinza
39 : @project Zorba/IO/Process42 : @project Zorba/IO/Process
40 :43 :
41 :)44 :)
@@ -44,7 +47,100 @@
44declare namespace an = "http://www.zorba-xquery.com/annotations";47declare namespace an = "http://www.zorba-xquery.com/annotations";
4548
46declare namespace ver = "http://www.zorba-xquery.com/options/versioning";49declare namespace ver = "http://www.zorba-xquery.com/options/versioning";
47declare option ver:module-version "1.0";50declare option ver:module-version "2.0";
51
52
53(:~
54 : Executes the specified program in a separate process.
55 : This function does not allow arguments to be passed to
56 : the command. The $filename parameter can contain the full path to the
57 : executable. On Linux systems, if the specified filename does not contain
58 : a slash "/", the function duplicates the actions of the shell in searching
59 : for an executable file. The file is sought in the colon-separated list of
60 : directory pathnames specified in the PATH environment variable. If this
61 : variable isn't defined, the path list defaults to the current directory
62 : followed by the list of directories returned by the operating system.
63 :
64 : @param $filename the name of program to be executed
65 :
66 : @return the result of the execution as an object as
67 : shown in the documentation of this module. The exit-code
68 : returns the exit code of the child process.
69 : For POSIX compliant platforms: returns the program exit code. If the program is
70 : terminated or stopped: 128 + termination signal code.
71 : For Windows platforms: returns the return value of the program or the exit
72 : or terminate process specified value.
73 :
74 : @error process:PROC01 if an error occurred while communicating
75 : with the executed process.
76 :)
77declare %an:sequential function process:exec(
78 $filename as xs:string
79) as object() external;
80
81(:~
82 : Executes the specified program in a separate process.
83 : The $filename parameter can contain the full path to the
84 : executable. On Linux systems, if the specified filename does not contain
85 : a slash "/", the function duplicates the actions of the shell in searching
86 : for an executable file. The file is sought in the colon-separated list of
87 : directory pathnames specified in the PATH environment variable. If this
88 : variable isn't defined, the path list defaults to the current directory
89 : followed by the list of directories returned by the operating system.
90 : The $args parameters will be passed to the executable file as arguments.
91 :
92 : @param $filename the name of program to be executed
93 : @param $args arguments to be passed to the executable
94 :
95 : @return the result of the execution as an object as
96 : shown in the documentation of this module. The exit-code
97 : returns the exit code of the child process.
98 : For POSIX compliant platforms: returns the program exit code. If the program is
99 : terminated or stopped: 128 + termination signal code.
100 : For Windows platforms: returns the return value of the program or the exit
101 : or terminate process specified value.
102 :
103 : @error process:PROC01 if an error occurred while communicating
104 : with the executed process.
105 :)
106declare %an:sequential function process:exec(
107 $filename as xs:string,
108 $args as xs:string*
109) as object() external;
110
111(:~
112 : Executes the specified program in a separate process.
113 : The $filename parameter can contain the full path to the
114 : executable. On Linux systems, if the specified filename does not contain
115 : a slash "/", the function duplicates the actions of the shell in searching
116 : for an executable file. The file is sought in the colon-separated list of
117 : directory pathnames specified in the PATH environment variable. If this
118 : variable isn't defined, the path list defaults to the current directory
119 : followed by the list of directories returned by the operating system.
120 : The $args parameters will be passed to the executable file as arguments.
121 : The $env allows defining and passing environment variables to the target
122 : process. They should be in the form "ENVVAR=value" where "ENVVAR" is the
123 : name of the environment variable and "value' is the string value to set it to.
124 :
125 : @param $filename the name of program to be executed
126 : @param $args arguments to be passed to the executable
127 :
128 : @return the result of the execution as an object as
129 : shown in the documentation of this module. The exit-code
130 : returns the exit code of the child process.
131 : For POSIX compliant platforms: returns the program exit code. If the program is
132 : terminated or stopped: 128 + termination signal code.
133 : For Windows platforms: returns the return value of the program or the exit
134 : or terminate process specified value.
135 :
136 : @error process:PROC01 if an error occurred while communicating
137 : with the executed process.
138 :)
139declare %an:sequential function process:exec(
140 $filename as xs:string,
141 $args as xs:string*,
142 $env as xs:string*
143) as object() external;
48144
49(:~145(:~
50 : Executes the specified string command in a separate process.146 : Executes the specified string command in a separate process.
@@ -64,9 +160,9 @@
64 : @error process:PROC01 if an error occurred while communicating 160 : @error process:PROC01 if an error occurred while communicating
65 : with the executed process.161 : with the executed process.
66 :)162 :)
67declare %an:sequential function process:exec(163declare %an:sequential function process:exec-command(
68 $cmd as xs:string164 $cmd as xs:string
69) as element(process:result) external;165) as object() external;
70166
71(:~167(:~
72 : Executes the specified string command in a separate process.168 : Executes the specified string command in a separate process.
@@ -87,7 +183,7 @@
87 : @error process:PROC01 if an error occurred while communicating 183 : @error process:PROC01 if an error occurred while communicating
88 : with the executed process.184 : with the executed process.
89 :)185 :)
90declare %an:sequential function process:exec(186declare %an:sequential function process:exec-command(
91 $cmd as xs:string,187 $cmd as xs:string,
92 $args as xs:string*188 $args as xs:string*
93) as element(process:result) external;189) as object() external;
94190
=== modified file 'src/com/zorba-xquery/www/modules/process.xq.src/process.cpp'
--- src/com/zorba-xquery/www/modules/process.xq.src/process.cpp 2012-12-05 17:29:38 +0000
+++ src/com/zorba-xquery/www/modules/process.xq.src/process.cpp 2013-05-17 14:51:23 +0000
@@ -25,7 +25,6 @@
2525
26#ifdef WIN3226#ifdef WIN32
27# include <windows.h>27# include <windows.h>
28
29# ifndef NDEBUG28# ifndef NDEBUG
30# define _CRTDBG_MAP_ALLOC29# define _CRTDBG_MAP_ALLOC
31# include <stdlib.h>30# include <stdlib.h>
@@ -49,6 +48,20 @@
4948
50#include "process.h"49#include "process.h"
5150
51// Provde the execvpe() function since some platforms don't have it
52#ifndef WIN32
53int execvpe(const char *program, char **argv, char **envp)
54{
55 char **saved = environ;
56 int rc;
57 environ = envp;
58 rc = execvp(program, argv);
59 environ = saved;
60 return rc;
61}
62#endif
63
64
52namespace zorba {65namespace zorba {
53namespace processmodule {66namespace processmodule {
5467
@@ -100,6 +113,28 @@
100 aFactory->createTextNode(lExitCode, lExitCodeString.str());113 aFactory->createTextNode(lExitCode, lExitCodeString.str());
101}114}
102115
116void create_result_object(
117 zorba::Item& aResult,
118 const std::string& aStandardOut,
119 const std::string& aErrorOut,
120 int aExitCode,
121 zorba::ItemFactory* aFactory)
122{
123 std::vector<std::pair<zorba::Item,zorba::Item> > pairs;
124
125 pairs.push_back(std::pair<zorba::Item,zorba::Item>(aFactory->createString("exit-code"), aFactory->createInt(aExitCode)));
126 pairs.push_back(std::pair<zorba::Item,zorba::Item>(aFactory->createString("stdout"), aFactory->createString(aStandardOut)));
127 pairs.push_back(std::pair<zorba::Item,zorba::Item>(aFactory->createString("stderr"), aFactory->createString(aErrorOut)));
128
129 aResult = aFactory->createJSONObject(pairs);
130}
131
132void free_char_vector(std::vector<char*> argv)
133{
134 for (unsigned int i=0; i<argv.size(); i++)
135 free(argv[i]);
136}
137
103#ifdef WIN32138#ifdef WIN32
104139
105/***********************************************140/***********************************************
@@ -307,7 +342,7 @@
307#define READ 0342#define READ 0
308#define WRITE 1343#define WRITE 1
309344
310pid_t zorba_popen(const char *command, int *infp, int *outfp, int *errfp)345pid_t exec_helper(int *infp, int *outfp, int *errfp, const char *command, char* argv[], char* env[])
311{346{
312 int p_stdin[2];347 int p_stdin[2];
313 int p_stdout[2];348 int p_stdout[2];
@@ -332,7 +367,13 @@
332 close(p_stderr[READ]);367 close(p_stderr[READ]);
333 dup2(p_stderr[WRITE], 2); // duplicate stderr368 dup2(p_stderr[WRITE], 2); // duplicate stderr
334369
335 execl("/bin/sh", "sh", "-c", command, NULL);370 if (command)
371 execl("/bin/sh", "sh", "-c", command, NULL);
372 else if (env == NULL)
373 execvp(argv[0], argv);
374 else
375 execvpe(argv[0], argv, env);
376
336 perror("execl"); // output the result to standard error377 perror("execl"); // output the result to standard error
337 exit(errno);378 exit(errno);
338 }379 }
@@ -358,10 +399,23 @@
358 399
359 return pid;400 return pid;
360}401}
402
361#endif403#endif
362404
405
363/******************************************************************************406/******************************************************************************
364 *****************************************************************************/407 *****************************************************************************/
408String ExecFunction::getOneStringArgument (const Arguments_t& aArgs, int aPos) const
409{
410 Item lItem;
411 Iterator_t args_iter = aArgs[aPos]->getIterator();
412 args_iter->open();
413 args_iter->next(lItem);
414 zorba::String lTmpString = lItem.getStringValue();
415 args_iter->close();
416 return lTmpString;
417}
418
365zorba::ItemSequence_t419zorba::ItemSequence_t
366ExecFunction::evaluate(420ExecFunction::evaluate(
367 const Arguments_t& aArgs,421 const Arguments_t& aArgs,
@@ -370,6 +424,7 @@
370{424{
371 std::string lCommand;425 std::string lCommand;
372 std::vector<std::string> lArgs;426 std::vector<std::string> lArgs;
427 std::vector<std::string> lEnv;
373 int exit_code = 0;428 int exit_code = 0;
374429
375 lCommand = getOneStringArgument(aArgs, 0).c_str();430 lCommand = getOneStringArgument(aArgs, 0).c_str();
@@ -379,12 +434,20 @@
379 zorba::Item lArg;434 zorba::Item lArg;
380 Iterator_t arg1_iter = aArgs[1]->getIterator();435 Iterator_t arg1_iter = aArgs[1]->getIterator();
381 arg1_iter->open();436 arg1_iter->open();
382 while (arg1_iter->next(lArg))437 while (arg1_iter->next(lArg))
383 {
384 lArgs.push_back(lArg.getStringValue().c_str());438 lArgs.push_back(lArg.getStringValue().c_str());
385 }
386 arg1_iter->close();439 arg1_iter->close();
387 }440 }
441
442 if (aArgs.size() > 2)
443 {
444 zorba::Item lArg;
445 Iterator_t arg1_iter = aArgs[2]->getIterator();
446 arg1_iter->open();
447 while (arg1_iter->next(lArg))
448 lEnv.push_back(lArg.getStringValue().c_str());
449 arg1_iter->close();
450 }
388451
389 std::ostringstream lTmp;452 std::ostringstream lTmp;
390453
@@ -432,18 +495,38 @@
432 int errfp;495 int errfp;
433 int status;496 int status;
434 pid_t pid;497 pid_t pid;
498
499 std::vector<char*> argv(lArgs.size()+2, NULL);
500 std::vector<char*> env(lEnv.size()+1, NULL);
435501
436 pid = zorba_popen(lTmp.str().c_str(), NULL, &outfp, &errfp);502 try
437 if ( pid == -1 )503 {
438 {504 if (theIsExecProgram)
439 std::stringstream lErrorMsg;505 {
440 lErrorMsg << "Failed to execute the command (" << pid << ")";506 argv[0] = strdup(lCommand.c_str());
441 Item lQName = ProcessModule::getItemFactory()->createQName(507 for (unsigned int i=0; i<lArgs.size(); i++)
442 "http://www.zorba-xquery.com/modules/process", "PROC01");508 argv[i+1] = strdup(lArgs[i].c_str());
443 throw USER_EXCEPTION(lQName, lErrorMsg.str().c_str());509
444 }510 for (unsigned int i=0; i<lEnv.size(); i++)
445 else511 env[i] = strdup(lEnv[i].c_str());
446 {512
513 pid = exec_helper(NULL, &outfp, &errfp, NULL, argv.data(), lEnv.size() ? env.data() : NULL);
514 }
515 else
516 {
517 pid = exec_helper(NULL, &outfp, &errfp, lTmp.str().c_str(), argv.data(), NULL);
518 }
519
520 if ( pid == -1 )
521 {
522 std::stringstream lErrorMsg;
523 lErrorMsg << "Failed to execute the command (" << pid << ")";
524 Item lQName = ProcessModule::getItemFactory()->createQName(
525 "http://www.zorba-xquery.com/modules/process", "PROC01");
526 throw USER_EXCEPTION(lQName, lErrorMsg.str().c_str());
527 return NULL;
528 }
529
447 char lBuf[PATH_MAX];530 char lBuf[PATH_MAX];
448 ssize_t length = 0;531 ssize_t length = 0;
449 while ( (length=read(outfp, lBuf, PATH_MAX)) > 0 )532 while ( (length=read(outfp, lBuf, PATH_MAX)) > 0 )
@@ -504,28 +587,23 @@
504 }587 }
505 588
506 //std::cout << " exit_code : " << exit_code << std::endl; std::cout.flush();589 //std::cout << " exit_code : " << exit_code << std::endl; std::cout.flush();
507590 free_char_vector(argv);
591 free_char_vector(env);
592 }
593 catch (...)
594 {
595 free_char_vector(argv);
596 free_char_vector(env);
597 throw;
508 }598 }
509#endif // WIN32599#endif // WIN32
510600
511 zorba::Item lResult;601 zorba::Item lResult;
512 create_result_node(lResult, lStdout.str(), lStderr.str(), exit_code,602 create_result_object(lResult, lStdout.str(), lStderr.str(), exit_code,
513 theModule->getItemFactory());603 theModule->getItemFactory());
514
515 return zorba::ItemSequence_t(new zorba::SingletonItemSequence(lResult));604 return zorba::ItemSequence_t(new zorba::SingletonItemSequence(lResult));
516}605}
517606
518String ExecFunction::getOneStringArgument (const Arguments_t& aArgs, int aPos)
519 const
520{
521 Item lItem;
522 Iterator_t args_iter = aArgs[aPos]->getIterator();
523 args_iter->open();
524 args_iter->next(lItem);
525 zorba::String lTmpString = lItem.getStringValue();
526 args_iter->close();
527 return lTmpString;
528}
529607
530/******************************************************************************608/******************************************************************************
531 *****************************************************************************/609 *****************************************************************************/
@@ -545,10 +623,14 @@
545 zorba::ExternalFunction*& lFunc = theFunctions[aLocalname];623 zorba::ExternalFunction*& lFunc = theFunctions[aLocalname];
546 if (lFind == theFunctions.end())624 if (lFind == theFunctions.end())
547 {625 {
548 if (!aLocalname.compare("exec"))626 if (aLocalname.compare("exec-command") == 0)
549 {627 {
550 lFunc = new ExecFunction(this);628 lFunc = new ExecFunction(this);
551 }629 }
630 else if (aLocalname.compare("exec") == 0)
631 {
632 lFunc = new ExecFunction(this, true);
633 }
552 }634 }
553 return lFunc;635 return lFunc;
554}636}
555637
=== modified file 'src/com/zorba-xquery/www/modules/process.xq.src/process.h'
--- src/com/zorba-xquery/www/modules/process.xq.src/process.h 2012-07-21 01:09:37 +0000
+++ src/com/zorba-xquery/www/modules/process.xq.src/process.h 2013-05-17 14:51:23 +0000
@@ -74,12 +74,13 @@
74class ExecFunction : public ContextualExternalFunction74class ExecFunction : public ContextualExternalFunction
75{75{
76public:76public:
77 ExecFunction(const ProcessModule* aModule) : theModule(aModule) {}77 ExecFunction(const ProcessModule* aModule, bool aExecProgram = false)
78 : theModule(aModule), theIsExecProgram(aExecProgram) {}
7879
79 virtual ~ExecFunction() {}80 virtual ~ExecFunction() {}
8081
81 virtual zorba::String82 virtual zorba::String
82 getLocalName() const { return "exec"; }83 getLocalName() const { if (theIsExecProgram) return "exec"; else return "exec-command"; }
8384
84 virtual zorba::ItemSequence_t85 virtual zorba::ItemSequence_t
85 evaluate(const Arguments_t&,86 evaluate(const Arguments_t&,
@@ -93,12 +94,14 @@
9394
94protected:95protected:
95 const ProcessModule* theModule;96 const ProcessModule* theModule;
97
98 bool theIsExecProgram; // if set to true, will use the execvpe() version of the system function
99 // if set to false, will build a command string and pass it to
100 // either "bash" or "cmd.exe" (through execl() on Linux)
96101
97 String getOneStringArgument (const Arguments_t& aArgs, int index) const;102 String getOneStringArgument (const Arguments_t& aArgs, int index) const;
98};103};
99104
100
101
102} /* namespace processmodule */105} /* namespace processmodule */
103} /* namespace zorba */106} /* namespace zorba */
104107
105108
=== added file 'test/ExpQueryResults/process2-01.xml.res'
--- test/ExpQueryResults/process2-01.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/process2-01.xml.res 2013-05-17 14:51:23 +0000
@@ -0,0 +1,1 @@
1true
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/ExpQueryResults/process2-02.xml.res'
--- test/ExpQueryResults/process2-02.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/process2-02.xml.res 2013-05-17 14:51:23 +0000
@@ -0,0 +1,1 @@
1true
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/ExpQueryResults/process2-03.xml.res'
--- test/ExpQueryResults/process2-03.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/process2-03.xml.res 2013-05-17 14:51:23 +0000
@@ -0,0 +1,1 @@
1true
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/ExpQueryResults/process2-04.xml.res'
--- test/ExpQueryResults/process2-04.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/process2-04.xml.res 2013-05-17 14:51:23 +0000
@@ -0,0 +1,1 @@
1true
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/ExpQueryResults/process2-05.xml.res'
--- test/ExpQueryResults/process2-05.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/process2-05.xml.res 2013-05-17 14:51:23 +0000
@@ -0,0 +1,1 @@
1true
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/ExpQueryResults/process2-06.xml.res'
--- test/ExpQueryResults/process2-06.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/process2-06.xml.res 2013-05-17 14:51:23 +0000
@@ -0,0 +1,1 @@
1true
0\ No newline at end of file2\ No newline at end of file
13
=== modified file 'test/Queries/process.xq'
--- test/Queries/process.xq 2011-08-13 00:08:53 +0000
+++ test/Queries/process.xq 2013-05-17 14:51:23 +0000
@@ -2,22 +2,22 @@
22
33
4{4{
5 variable $stdOutTest := proc:exec("echo","hello world") ;5 variable $stdOutTest := proc:exec-command("echo","hello world") ;
6 variable $stdErrTest := proc:exec("echo","Ooops. an error. 1>&amp;2");6 variable $stdErrTest := proc:exec-command("echo","Ooops. an error. 1>&amp;2");
7 variable $stdOutWinTest := proc:exec("cmd", ("/c", "echo","hello world")) ;7 variable $stdOutWinTest := proc:exec-command("cmd", ("/c", "echo","hello world")) ;
8 variable $stdErrWinTest := proc:exec("cmd", ("/c", "echo","Ooops. an error. 1>&amp;2"));8 variable $stdErrWinTest := proc:exec-command("cmd", ("/c", "echo","Ooops. an error. 1>&amp;2"));
9 9
10 let $result :=10 let $result :=
11 <result>11 <result>
12 <out>{normalize-space(data($stdOutTest/proc:stdout))}</out>12 <out>{normalize-space(data($stdOutTest("stdout")))}</out>
13 <err>{normalize-space(data($stdErrTest/proc:stderr))}</err>13 <err>{normalize-space(data($stdErrTest("stderr")))}</err>
14 </result>14 </result>
15 return 15 return
16 if (contains($result/err/text(),"is not recognized as an internal or external command"))16 if (contains($result/err/text(),"is not recognized as an internal or external command"))
17 then17 then
18 <result>18 <result>
19 <out>{normalize-space(data($stdOutWinTest/proc:stdout))}</out>19 <out>{normalize-space(data($stdOutWinTest("stdout")))}</out>
20 <err>{normalize-space(data($stdErrWinTest/proc:stderr))}</err>20 <err>{normalize-space(data($stdErrWinTest("stderr")))}</err>
21 </result>21 </result>
22 else22 else
23 $result23 $result
2424
=== added file 'test/Queries/process2-01.xq'
--- test/Queries/process2-01.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/process2-01.xq 2013-05-17 14:51:23 +0000
@@ -0,0 +1,5 @@
1import module namespace proc = "http://www.zorba-xquery.com/modules/process";
2
3let $result := proc:exec("echo")
4return $result("stdout") eq "
5"
06
=== added file 'test/Queries/process2-02.xq'
--- test/Queries/process2-02.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/process2-02.xq 2013-05-17 14:51:23 +0000
@@ -0,0 +1,5 @@
1import module namespace proc = "http://www.zorba-xquery.com/modules/process";
2
3let $result := proc:exec("echo",("hello","world"))
4return $result("stdout") eq "hello world
5"
06
=== added file 'test/Queries/process2-03.xq'
--- test/Queries/process2-03.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/process2-03.xq 2013-05-17 14:51:23 +0000
@@ -0,0 +1,5 @@
1import module namespace proc = "http://www.zorba-xquery.com/modules/process";
2
3let $result := proc:exec("printenv",("TEST_ENV_VAR"),"TEST_ENV_VAR=foo")
4return $result("stdout") eq "foo
5"
06
=== added file 'test/Queries/process2-04.xq'
--- test/Queries/process2-04.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/process2-04.xq 2013-05-17 14:51:23 +0000
@@ -0,0 +1,6 @@
1import module namespace proc = "http://www.zorba-xquery.com/modules/process";
2
3let $result := proc:exec("printenv",("TEST_ENV_VAR","VAR2"),("TEST_ENV_VAR=foo","VAR2=bar"))
4return $result("stdout") eq "foo
5bar
6"
07
=== added file 'test/Queries/process2-05.xq'
--- test/Queries/process2-05.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/process2-05.xq 2013-05-17 14:51:23 +0000
@@ -0,0 +1,5 @@
1import module namespace proc = "http://www.zorba-xquery.com/modules/process";
2
3let $result := proc:exec("echo","{}[]()()''~!@#$%^&amp;*_-+|<>/?,.")
4return $result("stdout") eq "{}[]()()''~!@#$%^&amp;*_-+|<>/?,.
5"
06
=== added file 'test/Queries/process2-06.xq'
--- test/Queries/process2-06.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/process2-06.xq 2013-05-17 14:51:23 +0000
@@ -0,0 +1,4 @@
1import module namespace proc = "http://www.zorba-xquery.com/modules/process";
2
3let $result := proc:exec("this_executable_does_not_exist")
4return $result("exit-code") ne 0

Subscribers

People subscribed via source and target branches

to all changes: