It is possible to run URL or path with external program from Haxe?
Something like a Process.Start("C:\") in C# will be opened drive C in file windows explorer (or Process.Start("/home/user/Desktop") will open Caja with this path in Linux Mint), or somethink like a package "Open" in NodeJS (it will do the same).
Or I need to open some text file with text editor, what selected in system by default.
Or when I try to run URL, then must be opened default web-browser with this address.
I think I can do this little code:
public static function execUrl (url:String) : Void {
switch (Sys.systemName()) {
case "Linux", "BSD": Sys.command("xdg-open", [url]);
case "Mac": Sys.command("open", [url]);
case "Windows": Sys.command("start", [url]);
default:
}
}
in unix-like systems can be used program "xdg-open". it know how to run needed path/url, and in windows this can do program "start"
Related
I have a C++ project that I have converted into javascript using emscripten. I need help with implementing file input into the program via node. As I understand it the default file system in emscripten uses preloaded data that can only be done on a web page or web worker. I need mine to work with node.js on the command line.
Looking at the documentation I see that there's a way to use NODEFS instead of the default MEMFS which should allow me to do this. However, I'm unsure how I'm supposed to go about this. I don't really understand the test code that's provided.
Here's how the file handling is being done in the original C++ project:
void InputFile(std::string &fileName)
{
std::ifstream in(fileName);
if (in.fail())
{
std::cerr << "ERROR, Could not open " << fileName << std::endl;
exit(1);
}
}
But when I attempt to run the converted program with a file, node project.js -f test.file I get the error message: ERROR, Could not open test.file meaning that opening the file failed. The original C++ project was able to open the file without any issues, so I know there's not problem with the file itself.
I'm not sure what I have to do to make the converted project work with file inputs, any help would very much appreciated.
Explanation
WebAssembly module, built using emscripten, has no information about files in your physical file system. Instead, it uses a virtual file system. All you have to do is to create a link between files on your physical system to the files on the module's virtual system. NODEFS gives you this opportunity.
Quick solution
We will start at modifying your C++ code by adding the aforementioned link between physical and virtual file systems using embedded JS code (with EM_ASM). First (1), we create a directory '/temp' on the virtual file system where all referenced files will be located in. Then (2), we link this new virtual directory with a real physical location (the current working directory '.') where all the referenced files are already.
#include <emscripten.h>
#include <emscripten/bind.h>
#include <iostream>
#include <fstream>
void InputFile(const std::string &fileName)
{
EM_ASM(
FS.mkdir('/temp'); // (1)
FS.mount(NODEFS, {root : '.'}, '/temp');); // (2)
std::ifstream in(std::string("/temp/") + fileName);
if (in.fail())
{
std::cerr << "ERROR, Could not open " << fileName << std::endl;
exit(1);
}
}
EMSCRIPTEN_BINDINGS(Module)
{
emscripten::function("InputFile", &InputFile);
}
Now, because in the WebAssembly module, we are working with the virtual file systems, and not the physical one, each referenced file from the current directory (the root '.') is actually in the virtual directory previously linked ('/temp'). Hence, '/temp' directory precedes the name to the referenced file: std::ifstream in(std::string("/temp/") + fileName);.
Finally, we can compile this file. We force the synchronized compilation (to make sure the require loads the WASM module on time). Moreover, the option -s EXIT_RUNTIME=1 makes sure that the C++ command exit(1); finishes the execution. Also, we need to link Embind (--bind) and NODEFS (-lnodefs.js):
emcc project.cpp -o project.js -s WASM_ASYNC_COMPILATION=0 -s EXIT_RUNTIME=1 --bind -lnodefs.js
Testing
To test the WebAssembly module with the same calling convention as you have mentioned, we can use the following test.js script:
var Module = require('./project.js');
if (process.argv[3] && process.argv[2] === '-f') {
const filename = process.argv[3];
Module.InputFile(filename);
} else {
console.log('Pass the file with -f flag!');
}
To run the file, all you have to do is this: node test.js -f test.file
Comment
This approach works well if the referenced files are in the current working directory. In the case they are not, you could modify the code of the InputFile to extract the directory in which the fileName is, and then, mount the real-to-virtual directory accordingly.
I'm building a desktop app for Windows using electron-packager and electron-squirrel-startup, I would like to execute some Windows cmd commands during the installation of my application. To do so I was planning to use node-cmd node module, but I doesn't really work inside the handleSquirrelEvents function. An example command like this:
function handleSquirrelEvent(application) {
const squirrelEvent = process.argv[1];
switch (squirrelEvent) {
case '--squirrel-install':
case '--squirrel-updated':
var cmd=require('node-cmd');
cmd.run('touch example.created.file');
}
};
Seems to work. A file example.created.file in my_app/node_module/node-cmd/example directory is created.
But any other code does not work. Even if I only change the name of the file to be "touched" nothing happens.
Ok, example.created.file already exists in this directory and I suspect that you can only use update.exe supported commands in case '--squirrel-updated' sections. So this will not work.
I need to open a kernel module created in Windows with a userland program
compiled in Cygwin; from Windows I can open it by using
CreateFile("\\\\.\\deviceName",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL)
but in Cygwin if I try to use the
open("//deviceName", O_RDWR);
nothing happens; I've tried to use "\DosDevices\deviceName", //deviceName,
//DosDevices/deviceName etc.... but I'm unable to open the device.
There is a way to do this in Cygwin or I must use the CreateFile in the
userland application?
EDIT:
FYI in the kernel module the link is created this way after calling correctly a IoCreateDevice(....)
#define DOS_DEVICE_NAME L"\\DosDevices\\deviceName"
...
RtlInitUnicodeString( &ntWin32NameString, DOS_DEVICE_NAME );
ntStatus = IoCreateSymbolicLink(&ntWin32NameString, &ntUnicodeString );
....
EDIT2:
Using Sysinternals WinObj I can correctly see my device under
\GLOBAL?? with the symlink \Device\deviceName
Ok, it seems that I've been able to find it: it is specified under
"/proc/sys/DosDevices/Global/deviceName"
and can be opened with
fd = open("/proc/sys/DosDevices/Global/deviceName", O_RDWR);
I followed the tutorial (In the "Getting Started" section) on how to use TiddlyWiki with node-webkit. When I then run nw.exe it doesn't display anything.
Im on windows (64bit) and have installed the 32bit version for windows. Not sure what Im doing wrong or if its just a bug.
I have also tried adding index.html and package.json to an archive (called app.nw) and run it with nw.exe, but still no luck.
I followed the instructions and couldn't get it to work either. I used TiddlyWiki 5.0.13-beta, Windows 64 bit, node-webkit 0.9.2. It throws an exception that it can't find sjcl.js. sjcl.js is packaged into TiddlyWiki.
I suggest to use TiddlyDesktop instead. It's node-webkit ready-made for TiddlyWiki. It works like a charm for me under Windows. You can get it here:
https://github.com/Jermolene/TiddlyDesktop/releases
I suspect the plain node-webkit solution has lost attention, now that there is TiddlyDesktop.
The offending code is in bootprefix.js. When bootprefix runs it checks if it is using node and then assumes it is a Node JS file based system. One solution, on a per-TiddlyWiki basis is to modify the following code near the top of bootprefix.js, which is in a script tag in single file TiddlyWiki.
// Detect platforms
$tw.browser = typeof(window) !== "undefined" ? {} : null;
$tw.node = typeof(process) === "object" ? {} : null;
$tw.nodeWebKit = $tw.node && global.window && global.window.nwDispatcher ? {} : null;
if($tw.nodeWebKit) $tw.node = null; //this is the line to add.
I have installed sublime2, package control module and nodejs through it.
After opening my js application I am getting next error, when try to run my application Tools->NodeJS->Run.
File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 445, in is_enabled_
raise ValueError("is_enabled must return a bool", self)
ValueError: ('is_enabled must return a bool', <Nodejs.Nodejs.NodeUglifyCommand object at 0x10f70bc90>)
All items in the menu are disabled.
Also I have tried modify user settings use next one:
{
// save before running commands
"save_first": true,
// if present, use this command instead of plain "node"
// e.g. "/usr/bin/node" or "C:\bin\node.exe"
"node_command": "/usr/local/bin/node",
// Same for NPM command
"npm_command": "/usr/local/bin/npm",
// as 'NODE_PATH' environment variable for node runtime
"node_path": "/usr/local/Cellar/node/0.10.25",
"expert_mode": false,
"ouput_to_new_tab": false
}
I have installed node via brew.
I had the same problem with my custom build system. The solution is just to choose the build system you want to use.
There must be checkmark alongside some build system in Tools->Build System