Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


DuraTechDev
2019-01-30T21:58:31Z
I am trying to send the results of a SQL query to a NodeJS script for format manipulation. In this particular use case, I am converting the result set into an HTML table that I want to send back into an email task. I have the result set coming in from the query. I have the node script running and it returns data that I can see in the output. My issue is, the data does not seem to be piping into the script the way I assumed it would.

UserPostedImage

There is an exception: "Exception in Task: StandardIn has not been redirected."

This could be where my error is:

UserPostedImage

I am using the {TASK(PrevTask|StdOut)} in the StdIn field which may not be appropriate...

And my script is relatively simple:
var fs = require('fs');
let data = [];
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function () {
    var chunk;
    while ((chunk = process.stdin.read()) !== null) {
        data.push(chunk);
    }

    let table;
    table += data.join('~');
    //add styleing
    table = `<style>td { border: solid 2px black;padding:0.25em;}</style>`;
    table += `<table>`;
    for (let i = 0; i < data.length; i++) {
        let columns = data[i].split('~');
        if (columns.length > 0) {
            table += `<tr>`;
            for (let k = 0; k < columns.length; k++) {
                if (i == 0) {
                    table += '<th>' + columns[k] + '</th>';
                } else {
                    if (isNaN(parseInt(columns[k]))) {
                        table += `<td style="${(i%2==0? 'background-color: #DDD;' : '')}">` + columns[k] + '</td>';
                    } else {
                        table += `<td style="text-align:center;${(i%2==0? 'background-color: #DDD;' : '')}">` + columns[k] + '</td>';
                    }

                }
            }
            table += '</tr>';
        }
    }
    table += '</table>';
    fs.writeSync(1, table);
    process.exit(0);

});
Sponsor
Forum information
Support
2019-02-05T17:04:44Z
Can you please add a screenshot of the full window so we can see all settings?
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
DuraTechDev
2019-02-05T17:48:49Z
Here is the execute task full window:
Execute Task full window
DuraTechDev
2019-02-05T22:58:10Z
I figured out a different way to pass my data instead of using the StdIn field. I am passing it as an argument instead.
I believe the difference here is that I changed the output from SQL to use the '~' instead of '|' characters. I would still like to know the proper way to pipe data into my nodejs script in case the need arises in the future.

Edit execute task with "{TASK(PrevTask|StdOut)}" as a second argument.

var fs = require('fs');
let data = process.argv[2].split('\r\n');

let table;
//add styleing
table = `<style>td { border: solid 2px black;padding:0.25em;}</style>`;
table += `<table>`;
for (let i = 0; i < data.length; i++) {
    let columns = data[i].split('~');
    if (columns.length > 0) {
        table += `<tr>`;
        for (let k = 0; k < columns.length; k++) {
            if (i == 0) {
                table += '<th>' + columns[k] + '</th>';
            } else {
                if (isNaN(parseInt(columns[k]))) {
                    table += `<td style="${(i%2==0? 'background-color: #DDD;' : '')}">` + columns[k] + '</td>';
                } else {
                    table += `<td style="text-align:center;${(i%2==0? 'background-color: #DDD;' : '')}">` + columns[k] + '</td>';
                }

            }
        }
        table += '</tr>';
    }
}
table += '</table>';
fs.writeSync(1, table);
process.exit(0);
Support
2019-02-06T20:50:52Z
Thanks, we will review std in and get back to you later.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Support
2019-02-18T11:20:06Z
Please test this build: https://www.visualcron.c....aspx?g=posts&t=9330 

Here you can choose if you want text or file as input.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
DuraTechDev
2019-02-18T19:34:14Z
Thank you! I was able to use this build to make it work. I was able to successfully pipe that data through the StdIn text field into my node script's stdin.

I have a new suggestion based on this. Would you like me to create a new post for it? My request is to have more Line Break and Field Separator options in the output tab for the SQL tasks. '|' works great because it isn't commonly used in our data sets, but sometimes there are carriage returns inside of the text fields I need to avoid splitting. It would be great if we could put in our own characters.
Support
2019-02-19T08:22:12Z
Originally Posted by: DuraTechDev 

Thank you! I was able to use this build to make it work. I was able to successfully pipe that data through the StdIn text field into my node script's stdin.

I have a new suggestion based on this. Would you like me to create a new post for it? My request is to have more Line Break and Field Separator options in the output tab for the SQL tasks. '|' works great because it isn't commonly used in our data sets, but sometimes there are carriage returns inside of the text fields I need to avoid splitting. It would be great if we could put in our own characters.



Sure, please request this.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Support
2022-02-09T12:42:08Z
Just wanted to report that this issue is now fixed. If you have any issues with it, please send us an email to support@visualcron.com
Michael
Support
http://www.visualcron.com 

Please like  VisualCron on facebook!
Scroll to Top