Node Webkit not running files that run in terminal

0 favourites
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Me?

  • 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.

  • 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?

  • 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 - >

    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;
    }
    [/code:jfljaaie]
    
    Example [h2](open cmd)[/h2] 
    [code:jfljaaie]
    start();
    send('cd c:\\users\\bob\\desktop \n start cmd');
    [/code:jfljaaie]
    
    edit : *fixed for multiline strings
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

    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

  • 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

  • I've written a plugin that pipes to cmd directly, and returns the shell response, but I won't release it.

    The double batch trick works fine. Make sure you've defined a global variable named cd and that you are previewing with node-webkit.

    Global text c:/users/bob/desktop/foo.bat

    On some event browser execute JS "require('child_process').execFile('"&cd&"');"

  • Noncentz705, i finally got it to work, thanks.

    I have a couple of questions though.

    1) how do i specify the directory to run a file in the app folder, this backward and forward slash things are causing problems?

    2) The same file i want to run with node-webkit, i would like to request it with ajax request url, for ajax request url, it just needs to be in the same folder with the executable, how can i work around this?

    I've written a plugin that pipes to cmd directly, and returns the shell response, but I won't release it.

    The double batch trick works fine. Make sure you've defined a global variable named cd and that you are previewing with node-webkit.

    Global text c:/users/bob/desktop/foo.bat

    On some event browser execute JS "require('child_process').execFile('"&cd&"');"

  • fixed most of the issues i had. thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)