[NWjs] Run *.bat or cmd from path

0 favourites
  • 13 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hi community!

    First off: this question isnt part of a game - Im playing arround with C2. I want to extend a console-automation I wrote for my company with a GUI (since making a GUI in PowerShell is a pain in the a.... without tools from SAPIEN or others...).

    I tryed a whole lot in making NWjs to open a *.bat or command prompt window. I can't figure out how to do that.

    Something of what I tried so far:

    • NWjs | Run "C:\Temp\my_bat_file.bat" // nope
    • NWjs | Run "C:\Windows\system32\cmd.exe" // nope
    • NWjs | Run "C:\Windows\SysWOW64\cmd.exe" // nope
    • NWjs | Run "cmd.exe" // nope
    • NWjs | Run "process.env.ComSpec + ' /c batfile.bat" // nope (whyever I thought that may works - found that while searching on Google - and yes, I pasted node.js code here... )

    Since launching a *.exe works fine just as it should, I downloaded a bat2exe complier and compiled my *.bat into an executable:

    • NWjs | Run "C:\Temp\my_bat_file.exe" // also: nope

    [everything else what I tried doesnt really made sense at all...]

    My batch just pings Google (8.8.8.8) so far - nothing special. I do not need any kind of automation/value-returning - the user should just see the opened command prompt window with its contents shown before a "pause"- interaction.

    I thought about security reasons why it isnt possible - but writing a malicious script in VS/vbs and compiling it into a native executable is just as easy as in a simple batch script - so I dont think that someone restricted that because of security reasons (obviously I do not want to write malicious software nor harm any system - just to have it said at this point!).

    Does someone know a work-arround for simply opening a *.bat - or if not otherwise possible a compiled *.exe from a *.bat script?

    Have a great weekend

    Proxy

    Edit: even the fail-safe method: NWjs Open Dialog, choosing file, Run NWjs.ChosenPath - doesnt work... I think this has nothing to do with a wrong path or such...

  • I hope this will work for you (I've not tried it). NWjs spawning .bat and .cmd

    Edit:

    If you include the .bat file inside the package.nw (ie import it into c2) then use:

    require('child_process').exec('cmd /c batfile.bat', function(){
       // …your callback code may run here…
    });[/code:1zu0bvrl]
  • I hope this will work for you (I've not tried it). NWjs spawning .bat and .cmd

    Edit:

    If you include the .bat file inside the package.nw (ie import it into c2) then use:

    require('child_process').exec('cmd /c batfile.bat', function(){
       // …your callback code may run here…
    });[/code:192a6lsf]
    

    Thanks, Colludium!

    Already took a look at that Wiki entry - but I hoped to realize that without modifing anything.

    I could also use ajax to realize that, but the main problem is, that I do not want to add anything into the C2 project. When starting the script/app you are prompted for 2 *.csv files, one contains software (vendor,name,path-to-exe, etc.) and one contains a collection of batch-files. The reason why Im doing it that way: not every machine has the same software and/or "functions/features" installed - because of that, you ll have multiple "Softwareconfiguration.csv"s and "Functionconfiguration.csv"s. Plus: when a new software is added to the system, you only have to add a row in one of the *.csv file; same with the "function" configuration. Its aimed to be multiusable without even thouching the C2 projectfiles... (you may know the wise words: "lazy admin is best admin" ).

    So all in all I want to compile the C2 project a single time and want to be able to extend the functionality anytime just by editing *.csv files (and last but not least, editing a *.csv file is much more easier for my collegues instead of opening C2 and editing something in the project itself (and of course, I own the license by myself, not in/for the company ).

    But well, if there isnt an another way, I have to mod the plugin.

    Thanks, anyway!

    Have a great weekend!

    Proxy

  • Try:

    NWjs | Run "start" for a CMD and

    NWjs | Run "start pathToBatFile" for a batch-file

    for example:

    NWjs | Run "start c:\mybat\batch.bat"

  • Try:

    NWjs | Run "start" for a CMD and

    NWjs | Run "start pathToBatFile" for a batch-file

    for example:

    NWjs | Run "start c:\mybat\batch.bat"

    You, sir, are a hero! <img src="{SMILIES_PATH}/icon_mrgreen.gif" alt=":mrgreen:" title="Mr. Green">

    Thanks! Works totally fine.

    [quote:1xceka4q]Run file

    Run the file at an existing file path. This is analogous to double-clicking the file in the OS file explorer. For executable programs, it will attempt to run the program; for other file types, it will open the default associated program, such as the system default image editor if an image file is given.

    https://www.scirra.com/manual/search?q=nwjs

    Would be worth mentioning there Ashley ;D

    Have a great weekend

    Proxy

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Try:

    NWjs | Run "start" for a CMD and

    NWjs | Run "start pathToBatFile" for a batch-file

    for example:

    NWjs | Run "start c:\mybat\batch.bat"

    This worked for me too, except when there are spaces in the file path, "c:\first folder\second folder\...". Somewhere I read that we should use double quotes (run | "start" """c:\first folder\..."""), but I haven't been able to make it work.

    Any ideas?

  • Try

    NWjs | Run "start c:\""first folder\second folder""\batch.bat"

    or with a folder in between without space

    NWjs | Run "start c:\""first folder""\folder\""second folder""\batch.bat"

  • Is this dangerous? Or is nw.js the desktop publisher?

  • Is it possible to use a path from an edit box / variable? can't seem to get the run command to work with a folder value the user chooses, which gets stored in an edit box and written to an ini file.

  • Ah got it working... did """"&editboxname.text&""""" (four speech quotes either side)

  • Just opening this up as I am trying to do the same thing. I want to run a .bat file so that I can download updated files for my app.

    I can write a .bat file that does it job and downloads to the installed NWJS directory. But the moment I am asking C2 to run the bat file (Like above) it does not function as expected.

    I have to put START at the beginning of my .bat file but this then for some reason stops it using the --ouput-document to save to the installed folder.

    Anyone know any work arounds?

  • BUMP to see if any one can help?

    Currently my .bat file is:

    "wget.exe" "https://drive.google.com/uc?export=download&id=1GfARdi3WQaCnxolZxL5Gnxamr" --output-document "%~dp0\packagetest.nw"

    This works when double clicking the file in explorer.

    When adding a command in C2 to run this:

    """" & NWjs.AppFolder & """" & "update.bat" & """" & """"

    It doesnt action it.

    Ashley is there something different by using NWJS to run a .bat file that is stopping this?

    Update:

    I have got it working but only when the project is placed in a location with no spaces in the directory "C:\test" for example.

    My C2 command is currently:

    "start " & NWjs.AppFolder & "update.bat"

    I just have not been able to get the double quotation marks in the right place to get this working for all locations?

    Currently I have tried:

    "start " & """" & NWjs.AppFolder & """" & "update.bat"

    "start " & """" & NWjs.AppFolder & "update.bat" & """"

    """" & "start " & NWjs.AppFolder & "update.bat" & """"

  • Try setting that expression to a text object and make sure that it actually matches what works from a command prompt.

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