set folder for Exec node

357 views
Skip to first unread message

Glenn

unread,
Apr 26, 2017, 2:29:03 AM4/26/17
to Node-RED
I was wondering if someone could help,

Currently using Windows batch files to do certain automated tasks.

I can run the batch files using the exec node.

Want I want to do is to replace the bat files with native node-red code.

Only problem is I don't know how to set the folder and then apply the command.

Eg. If I want to encrypt a file I want to use GPG in the folder location where the files are to be encrypted not the roaming folder.

Any tips would be great.

Julian Knight

unread,
Apr 26, 2017, 4:43:48 AM4/26/17
to Node-RED
It is generally up to the application to deal with paths so you should check out the docs for GPG. If you need to take control, the best way is to use a cmd or PowerShell batch file anyway. Both cmd and PowerShell have methods to get the current path so you can change folder.

If using Windows 10, it is better to bite the bullet and switch from cmd to PS as Microsoft seem intent on doing that at some point, PS is now the default shell on the latest release.

Glenn

unread,
Apr 26, 2017, 5:04:53 AM4/26/17
to Node-RED
Thanks. Already using PS and its great.

I don't want to be reliant on files eg if the PS script is deleted the node won't work but if its in the node natively less chance of problems.

I could just use a file node to list the filenames and then do a loop.

Or just use the script in the flow which defeats the purpose.

Julian Knight

unread,
Apr 26, 2017, 10:56:32 AM4/26/17
to Node-RED
If you know what folder you need to be in, you could change your command to something like:

cd my\folder\name && someterrible.exe

Glenn

unread,
Apr 26, 2017, 9:04:29 PM4/26/17
to Node-RED
Awesome thanks.

I'm sure i'll have more questions. But this is just the begining to breaking down massive bat files into manageable chunks.

I use the function node. But I would imagine you can do similar with the template node.

var directory = "cd " + msg.payload
var command = " &&  "selfdestruct -10"
msg.payload = directory + command
return msg;


Result c:\home\selfdestruct -t 10


 
Reply all
Reply to author
Forward
0 new messages