Community forum

Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
View
Go to last post Go to first unread
Offline DuraTechDev  
#1 Posted : Wednesday, January 30, 2019 10:58:31 PM(UTC)
DuraTechDev

Rank: Paid support

Joined: 11/12/2018(UTC)
Posts: 6
United States
Location: La Crosse, WI

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:
Code:
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);

});
Offline Support  
#2 Posted : Tuesday, February 5, 2019 6:04:44 PM(UTC)
Support

Rank: Official support

Joined: 2/23/2008(UTC)
Posts: 10,889

Thanks: 833 times
Was thanked: 414 time(s) in 392 post(s)
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!
Offline DuraTechDev  
#3 Posted : Tuesday, February 5, 2019 6:48:49 PM(UTC)
DuraTechDev

Rank: Paid support

Joined: 11/12/2018(UTC)
Posts: 6
United States
Location: La Crosse, WI

Here is the execute task full window:
Execute Task full window
Offline DuraTechDev  
#4 Posted : Tuesday, February 5, 2019 11:58:10 PM(UTC)
DuraTechDev

Rank: Paid support

Joined: 11/12/2018(UTC)
Posts: 6
United States
Location: La Crosse, WI

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.

Code:
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);

Edited by user Tuesday, February 5, 2019 11:59:00 PM(UTC)  | Reason: Not specified

Offline Support  
#5 Posted : Wednesday, February 6, 2019 9:50:52 PM(UTC)
Support

Rank: Official support

Joined: 2/23/2008(UTC)
Posts: 10,889

Thanks: 833 times
Was thanked: 414 time(s) in 392 post(s)
Thanks, we will review std in and get back to you later.
Henrik
Support
http://www.visualcron.com
Please like VisualCron on facebook!
Offline Support  
#6 Posted : Monday, February 18, 2019 12:20:06 PM(UTC)
Support

Rank: Official support

Joined: 2/23/2008(UTC)
Posts: 10,889

Thanks: 833 times
Was thanked: 414 time(s) in 392 post(s)
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!
Offline DuraTechDev  
#7 Posted : Monday, February 18, 2019 8:34:14 PM(UTC)
DuraTechDev

Rank: Paid support

Joined: 11/12/2018(UTC)
Posts: 6
United States
Location: La Crosse, WI

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.
Offline Support  
#8 Posted : Tuesday, February 19, 2019 9:22:12 AM(UTC)
Support

Rank: Official support

Joined: 2/23/2008(UTC)
Posts: 10,889

Thanks: 833 times
Was thanked: 414 time(s) in 392 post(s)
Originally Posted by: DuraTechDev Go to Quoted Post
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!
Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Scroll to Top