OSDN Git Service

modified work space
[eos/zephyr.git] / server / api / commandExecution / index.js
1 'use strict';
2
3 var express    = require('express'),
4     router     = express.Router(),
5     path       = require('path'),
6     exec       = require('child_process').exec
7
8 router.post('/', function(req, res) {
9     var params     = req.body,
10         command    = params.command,
11         inputPath  = path.normalize('workspace/'+params.inputDir),
12         outputPath = path.normalize('workspace/'+params.outputDir),
13         options    = params.options
14     var execLine = '/Users/hiratakengo/Eos/bin/X86MAC64/'+command
15     console.log(execLine)
16     if(options) {
17         options.forEach(function(option) {
18             if(option.isFilled) {
19                 var content = option.content.toString().replace(",", " ", "g")
20                 if(option.name === "-i") {
21                     execLine = execLine+' '+option.name+' '+path.normalize(inputPath+'/'+content)
22                 } else if(option.name === "-o") {
23                     execLine = execLine+' '+option.name+' '+path.normalize(outputPath+'/'+content)
24                 } else {
25                     execLine = execLine+' '+option.name+' '+content
26                 }
27             }
28         })
29     }
30     exec(execLine, function(err, stdout, stderr) {
31         if(err) {
32             console.error(err)
33             res.send('error')
34         } else {
35             console.log(stdout)
36             console.log(stderr)
37             res.send('done')
38         }
39     })
40 });
41
42 module.exports = router