Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another cjhild_process.exec issue with complex shell command

Status
Not open for further replies.

JPSeo

Systems Engineer
Sep 3, 2020
6
US
Hello:

Trying to run the following code but the arrays is not getting populated.

bash.cmd_4 works but bash.cmd_1 returns nothing.
I am guessing I am missing some delimiters.

Pls advise, Thank you !!

Code:
var array_id = new Array();

app.get('/qmgrs', function(req, res) {

    var QMGR    = req.param('qmgr');
    //var QMGR    = req.query.qmgr;

    var bash =
{
    cmd_1: `su mqm -c 'amqoamd -m ${QMGR} -s | egrep -iv \"system|mqm\"' |grep \"-n\"| awk \"{print $9}\"| sort -u`,
    cmd_4: `su mqm -c dspmq | grep ${QMGR}`
}

    cp.exec(bash.cmd_1, function(err, stdout, stderr) {
    if (err) {
       console.log(stderr)
    }
    else {
      array_id = stdout.split(/[\r\n|\n|\r]/).filter(String);
      console.log(array_id);

      //res.writeHead(200,{"Content-Type": "text/plain"});
      //res.end(stdout);

      res.render('users',{array_id: array_id});
    }
  });
});

Code:
<html>
  <head>
    <% include('header.ejs') %>
  </head>
  <body>
           <h1>App_ID List</h1>
           <h1>============</h1>
        <ul>
           <% for(var i=0; i<array_id.length; i++){ %>
           <!--  <h1><%= array_id[i] %></h1> -->
           <h1><a href="/users?app_id=<%= array_id[i] %>"><%= array_id[i] %></a></h1>
           <% } %>
        </ul>
  </body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top