Skip to content

Commit e0f83fb

Browse files
committed
example
1 parent 743874e commit e0f83fb

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

README.md

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,67 +21,82 @@ The diagram below should conceptually give you an idea of what this module does.
2121

2222
Its highly recommended you check out the unit-tests for some examples in addition to the below:
2323

24+
25+
### Example
2426
```
2527
var Promise = require('promise');
26-
var StatefulProcessCommandProxy = require("stateful-process-command-proxy");
28+
var StatefulProcessCommandProxy = require("./");
2729
2830
var statefulProcessCommandProxy = new StatefulProcessCommandProxy(
2931
{
3032
name: "test",
3133
max: 1,
3234
min: 1,
3335
idleTimeoutMillis: 10000,
34-
36+
3537
logFunction: function(severity,origin,msg) {
3638
console.log(severity.toUpperCase() + " " +origin+" "+ msg);
3739
},
3840
3941
processCommand: '/bin/bash',
4042
processArgs: ['-s'],
4143
processRetainMaxCmdHistory : 10,
42-
43-
processInvalidateOnRegex :
44+
45+
processInvalidateOnRegex :
4446
{
4547
'any':['.*error.*'],
4648
'stdout':['.*error.*'],
4749
'stderr':['.*error.*']
4850
},
49-
51+
5052
processCwd : './',
51-
processEnvMap : {"testVar1":"value1"},
53+
processEnvMap : {"testEnvVar":"value1"},
5254
processUid : null,
5355
processGid : null,
5456
55-
initCommands: [ 'echo Hellow World' ],
57+
initCommands: [ 'testInitVar=test' ],
5658
5759
validateFunction: function(processProxy) {
5860
return processProxy.isValid();
5961
},
6062
61-
preDestroyCommands: [ 'echo Goodbye!' ]
63+
preDestroyCommands: [ 'echo This ProcessProxy is being destroyed!' ]
6264
});
63-
65+
66+
statefulProcessCommandProxy.executeCommand('echo testEnvVar')
67+
.then(function(cmdResult) {
68+
console.log("testEnvVar value: Stdout: " + cmdResult.stdout);
69+
}).catch(function(error) {
70+
console.log("Error: " + error);
71+
});
72+
73+
statefulProcessCommandProxy.executeCommand('echo testInitVar')
74+
.then(function(cmdResult) {
75+
console.log("testInitVar value: Stdout: " + cmdResult.stdout);
76+
}).catch(function(error) {
77+
console.log("Error: " + error);
78+
});
79+
6480
// set a var in the shell
65-
statefulProcessCommandProxy.executeCommand('MY_VARIABLE=test1')
81+
statefulProcessCommandProxy.executeCommand('MY_VARIABLE=test1;echo MY_VARIABLE WAS JUST SET')
6682
.then(function(cmdResult) {
6783
console.log("Stdout: " + cmdResult.stdout);
68-
console.log("Stderr: " + cmdResult.stderr);
6984
}).catch(function(error) {
7085
console.log("Error: " + error);
7186
});
72-
87+
7388
// echo it back
7489
statefulProcessCommandProxy.executeCommand('echo $MY_VARIABLE')
7590
.then(function(cmdResult) {
76-
console.log("Stdout: " + cmdResult.stdout);
77-
console.log("Stderr: " + cmdResult.stderr
91+
console.log("MY_VARIABLE value: Stdout: " + cmdResult.stdout);
7892
}).catch(function(error) {
7993
console.log("Error: " + error);
8094
});
81-
95+
8296
setTimeout(function() {
8397
statefulProcessCommandProxy.shutdown();
8498
},5000);
99+
85100
```
86101

87102

0 commit comments

Comments
 (0)