Node Webkit not running files that run in terminal

Get help using Construct 2

Post » Wed May 28, 2014 5:04 pm

Thanks! I'll check this out. If it works then you are awesome! (Sadly, the project I originally needed this for is gone.) :(
Sorry about the username, old account XD
B
14
S
4
Posts: 69
Reputation: 1,404

Post » Wed May 28, 2014 5:59 pm

You usually want to tag Ashley in your thread if you want them to see your question. @Ashley
Twitter: https://twitter.com/pudgyplatypus

Learn to make a clicker game for cheap!
https://www.scirra.com/store/games-with ... e-game-666

Try out Pixel Golf on the Scirra Arcade!
https://www.scirra.com/arcade/sports-ga ... el-golf-67

Pudgy Platypus Games website!
www.pudgyplatypus.com
B
58
S
19
G
5
Posts: 212
Reputation: 7,310

Post » Sat May 31, 2014 6:01 pm

Ah thanks!
Sorry about the username, old account XD
B
14
S
4
Posts: 69
Reputation: 1,404

Post » Sat May 31, 2014 6:01 pm

@Ashley Could you take a look at this please?
Sorry about the username, old account XD
B
14
S
4
Posts: 69
Reputation: 1,404

Post » Sun Jun 01, 2014 12:22 pm

Why are you executing javascript directly and not using the 'run' action from the node-webkit object?
Scirra Founder
B
387
S
230
G
88
Posts: 24,251
Reputation: 192,454

Post » Tue Jun 10, 2014 6:51 pm

Me?
Sorry about the username, old account XD
B
14
S
4
Posts: 69
Reputation: 1,404

Post » Tue Jun 10, 2014 11:53 pm

Because somefile.bat launches in the background; Where it's not apparent whether or not the script even ran and the double bat trick doesn't work for me otherwise.
B
10
S
2
G
1
Posts: 202
Reputation: 1,555

Post » Thu Jul 17, 2014 2:39 am

@Noncentz705 take a look
http://www.nirsoft.net/utils/nircmd.html

I have to tried to run file from node-webkit action, then it won't work, meanwhile I clicked .exe to open command prompt and it inmediatly closes, I don't know why... Is needed to create bat files?
B
97
S
35
G
29
Posts: 3,139
Reputation: 28,361

Post » Thu Jul 17, 2014 7:49 am

You could spawn cmd as a child process and then pipe commands to it
which is what you want since it's being ran in the background already
too tired to write an addon for it - hope this is enough - >
Code: Select all
var isRunning = false,
   exec = require('child_process'),
   cmd = null;

function start(){if(isRunning) return; try{
   cmd = exec.spawn('cmd');
   isRunning = true;
   //..cmd response..
   //   cmd.stdout.on('data',function(data){console.log(data.toString());});
   //   cmd.stderr.on('data',function(data){console.log(data.toString());});
   } catch(e){/*Error*/}
}
function end(){if(!cmd || !isRunning) return; try{cmd.kill(); cmd=null; isRunning = false;} catch(e){throw e;}}
function send(data,cb){if(!cmd) return;
   data.split('\n').forEach(function(i){cmd.stdin.write(i+"\n",null,null);}); return cb? cb() : 0;
}


Example (open cmd)
Code: Select all
start();
send('cd c:\\users\\bob\\desktop \n start cmd');


edit : *fixed for multiline strings
B
10
S
2
G
1
Posts: 202
Reputation: 1,555

Post » Mon Aug 04, 2014 5:40 pm

@Noncentz705", please more light on this, i got this error log in my console. Thanks
Error executing Javascript:
ReferenceError {stack: (...), message: "require is not defined"}
message: "require is not defined"
stack: (...)
get stack: function () { [native code] }
set stack: function () { [native code] }
__proto__: Error
Browser_plugin.js:609
0

Noncentz705 wrote:Create two bat files :
File1.bat
start C:\Users\%username%\Desktop\project_folder\File2.bat
rem Notice I didn't use %cd%\File2.bat because preview runs from a temp folder;

File2.bat
echo CMD STARTED

Now in your project back in construct
- add the browser plugin to your project
- create a variable named cd and set it's value to the path of your first bat file with \\ 's

To launch cmd Browser Execute Javascript :
"require('child_process').execFile('"&cd&"');"

With that said there's probably a way easier way to do this :lol:
B
15
S
4
Posts: 138
Reputation: 2,003

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], imothep85, KTML5 and 1 guest