I am using angular-fullstack generator to create web app. Front end designed using angularjs and server side using nodejs. I have written a python function to know if a host is a linux host or not, which is invoked through nodejs and writes to a file 'This is a valid host' in case of valid linux host. If the host is linux host I want to redirect to different page. My angular code:
$scope.sendlogin = function () {
console.log("inside click");
var posting = $http({
method: 'POST',
url: '/login',
data: $scope.data,
processData: false
})
posting.success(function (response) {
$location.path("/vprobe");
});
}
My node code:
app.post('/login', function (req, res) {
/* Handling the AngularJS post request and storing in a file*/
var fs = require("fs");
console.log(req.body);
var jsonfile = require('jsonfile')
var file = 'login.json'
var obj = req.body;
jsonfile.writeFile(file, obj, function (err) {
console.error(err)
})
// invoking python child process
var exec = require('child_process').exec;
var arg = 'python checkvalidity.py'
exec(arg, function(error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
console.log('exec error: ' + error);
res.send(stdout);
});
});
But above code is not working correctly. For both stdout and stderr its redirecting to page. The stdout reads a file which has a content 'This is a valid host'. How to redirect only in case of stdout , and display a error in case of a error.
也许在您的nodeJs代码if(!stdout)中使用res.sendStatus(500)并使用.error(function(response))将其捕获到您的角度控制器中
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.