I'm in the process of writing a compiled C application which uses the system() function to launch a Java .jar file:
int main() {
system("java -jar MyJar.jar");
return 0;
}
I successfully wrapped this up in a clickable app bundle, however, when I double click it, the application exits immediately before it has a chance to launch the jar. However it works perfectly when I run the compiled C code from the command line.
Any insight would be appreciated!
Scott
The reason the application exits immediately is because of the following line:
return 0;
You would want to use exec instead of system. With exec, your program gets replaced by the Java process and never gets a chance to reach the return 0; line. However, it's much easier to just replace the entire C progrma with a shell script:
#!/bin/sh
exec java -jar MyJar.jar
As written, there is no drawback to this approach that I can think of. The C program already spawns a shell process (that's what system does), so why not start out with a shell process in the first place?
Lots of application bundles use shell scripts to do things like this.
Related
How to set exe4j to use javaW to execute the program?
I tried to use the GUI Application and still use java to run the program, which will cause my program to not execute normally.If you try to rename javaw to java, you will get an environment error.
exe4j creates launchers that use JNI to create the JVM. They do no call java or javaw. An exe4j launcher in console mode behaves similarly to java and an exe4j launcher in GUI mode behaves similarly to javaw.
I'm using yq to convert a YAML document into JSON for use in a C program. In my program, I convert the file to JSON using the command
system("yq ea \'[.]\' -o=json .cache/BT_nginx-ingress.yaml > .cache/package.json")
However this causes the error:
Error: write /dev/stdout: permission denied
Thoughout my program, I've used redirection several times with the system() command, but it fails in this specific instance.
I can run the command normally from the terminal, without root. I'm using bash on PopOS, so I've also added bash -c to the above system() call, but it fails this way too.
Can anyone help me with this? Thanks!
Edit: More details on my configuration. The current working directory is the same as the program's location which is one directory above .cache. The working directory is never changed. I am the owner of .cache and the files inside. The permissions are r/w for me, and the group. I am running the process but not with sudo. system("echo foo > .cache/package.json") works!
I have managed to fix this issue by adding the yq_linux_amd64 binary with the C program itself, rather than using the yq package from snap. It works fine now, and can redirect outputs without any issue.
I'm fairly new to jenkins. I'm trying to execute two .bat files(or directly two commands) from jenkin, the first one will startup selenium and the second will execute a test file (with protractor).
The problem is that when selenium is started, I no longer have hand to input more commands in the console.
I tried start cmd \k to get to another console, and CALLs for two different .bat file, but the console keeps showing the output the trace of selenium being executed.
How can I jump from the bloking console executing selenium to another console to execute my tests (while selenium is still being executed) ?
You could try something like this:
start powershell ".\IEDriverServer.exe"
Replacing the .exe file name with your executable.
I'm following the tutorial here and am stuck at "inserting parties from the console"... I can't run "meteor mongo"
Here is my output:
$ meteor.bat mongo
C:\Users\USER\AppData\Local\.meteor\packages\meteor-tool\1.1.4\mt-os.windows.x86_3 2\dev_bundle\lib\node_modules\fibers\future.js:245
throw(ex);
^ Error: EINVAL, invalid argument
at new Socket (net.js:157:18)
at process.stdin (node.js:687:19)
at Command.main.registerCommand.name [as func] (C:\Users\USER\AppData\Local\.m eteor\packages\meteor-tool\1.1.4\mt-os.windows.x86_32\tools\commands.js:1036:12)
at C:\Users\USER\AppData\Local\.meteor\packages\meteor-tool\1.1.4\mt-os.window s.x86_32\tools\main.js:1363:23
I'm using Cygwin on Windows 7 SP1, and have tried restarting to no use. In case this is relevant using control-C doesn't kill the meteor server, so I have been killing all the node.exe processes manually through the task manager instead.
This is my first time using meteor, and can't find this replicated anywhere.
** EDIT **
This works using the DOS prompt, but not the cygwin terminal
Thank you, and let me know if you need more info about anything!
At this time meteor on Windows can ONLY be used via the "cmd" prompt. Not even PowerShell will work. Nor does git-bash (in case you were wondering -- I tried that too).
Just do all your meteor commands from a "cmd" shell and you should avoid lots of little issues I think.
One nice thing -- when you want to build/deploy your app -- the nice little tool "demeteorizer" DOES work fine on cygwin/git-bash. :)
I have a MacRuby app, and after the app launches, I would like to launch a second process using an NSTask. The second process is a Ruby script bundled with the app. I would like to launch it using the MacRuby macruby interpreter that gets compiled into the app bundle. How can I do that?
First, remove the .rb extension from the ruby script, otherwise if you compile the macruby project using macruby_deploy, it will be compiled to rbo file. The script file should have this as its first line:
#!/usr/bin/env ruby
Make sure the script will be copied to Resources folder.
Then create and call a NSTask:
path = NSBundle.mainBundle.pathForResource('test', ofType:nil)
task = NSTask.alloc.init
task.setLaunchPath(path)
task.launch
Well, have you tried just calling NSTask?
NSTask.launchedTaskWithLaunchPath('script.rb', nil)
Then click around in Xcode to make sure that script.rb is in place during execution.