Fully detach ChildProcess in Rust on Windows - process

I need to relaunch a Rust application on Windows as administrator so I worked out a command that would do that for me.
After relaunching, I would like the initiating process to exit and the child to continue running. However, when the parent exits, the child exits too, which is undesired behavior in this case.
I have used the standard process:Command to launch the command (simplified here):
#![allow(unused)]
fn main() {
use std::process::Command;
use std::os::windows::io::IntoRawHandle;
let mut mycom = Command::new("C:\\Windows\\System32\\cmd.exe")
.arg("/C powershell -Command Start-Process -Verb runas -File-Path C:\\my\\file");
let child = mycom.spawn()
.expect("command failed to start");
//Perfectly running Child dies after pressing Enter
let mut s = String::new();
std::io::stdin().read_line(&mut s);
}
I found some documentation of .detached() and child.forget() here and here, however these options seem to be discontinued.
I also tried the Windows start command which also did not give me a detached process.
It's relatively easy on Linux by using nohup or mycommand &.
There may be a way with setsid in libc, but I didn't find any usable documentation for that, just the generated documentation.
Is there a way to achieve a fully detached process?

Related

How can I start the program without admin rights in VB.NET?

I have a problem I start an application with admin rights from this application, another application is started at the end. This then inherits the admin rights. But it should start with normal user rights. Does anyone have a solution for the problem or a tip?
The simplest way is to ask Explorer to start it for you:
Process.Start("explorer.exe", """C:\path to\your.exe""")
You can't pass any arguments to the exe - the exe name is already an argument to explorer and I don't believe there is a way to make explorer interpret the rest of what you give as arguments (to explorer) as "arguments that should be passed to the program being started"..
..but you could create a mini program that passes the relevant arguments and explorer start that mini instead.
'this is literally all the mini program does, then quits:
Process.Start("myactualprogram.exe", "some fixed arguments")
And your main elevated program does:
Process.Start("explorer.exe", """C:\path to\miniprogram.exe""")
--
"But what if the arguments aren't always fixed?" I hear you cry.. "How can I make my mini program do Process.Start("myactualprogram.exe", "varying arguments here") when all I can do is launch it by name?"
Well.. You could either make your actual program contact your first program via TCP sockets or something and ask it for info - interprocess communciation.. Or could write a file with the arguments that your actual program can pick up.. Or if the arguments are simple enough you could just rename (or copy) the mini program so it contains the arguments in its name and when it launches it can parse its own name
'myactualprogram.exe is expecting args of: varying arguments here
'the launcher is a winforms app called 'varying arguments here.exe' that has this code
Dim args = Path.GetFilenameWithoutExtension(Application.ExecutablePath)
Process.Start("myactualprogram", args)
Of course, if your program is expecting args like /out=c:\temp\file.txt then you'll have to get a lot more creative with itbecause you can't put / \ : in filenames.. how about base64 encoding the entire arg string, naming the file that, then having your launcher program decode the b64?

Remote debug Idea doesn't works for openresty

I am using mobDebug. If run a lua script from command line everything works.
But when I run them from openresty the Idea doesn't stop. It only writes "Connected/ Disconnected"
Configs:
location / {
access_by_lua_block {
local client = require("client")
}
client.lua:
local mobdebug = require("mobdebug");
mobdebug.start()
local lfs = require("lfs")
print("Folder: "..lfs.currentdir())
modebug debug_hook is not invoked for needed lines, set_breakpoints don't invoked.
Idea Debug Logs, but nothing occures:
Idea catch debug from terminal client.lua; But it miss it from running nginx.
THIS IS NOT AN ANSWER. It's just that I am experiencing basically the same problem, and comment space is too small to fit all the relevant observations I would like to share:
I was actually able to stop immediately after mobdebug.start() in code running in nginx, and to step-debug - but only in code called directly from init_by_lua_block. This code of course executes once during the server startup or config reload.
I was never able to stop in worker code (e.g. rewrite_by_lua_*). mobdebug.coro() didn't help, and mobdebug.on() threw about "attempt to yield across C-call boundary"
I was only ever able to stop one time, on next statement after mobdebug.start(); once I hit |> (Resume program), it won't stop on any further breakpoints.
Using mobdebug.loop() is not a correct way to do this, as it's used for live coding, which is not going to work as expected with this setup. mobdebug.start() should be used instead.
Please see an example of how this debugging can be setup with ZeroBrane Studio here: http://notebook.kulchenko.com/zerobrane/debugging-openresty-nginx-lua-scripts-with-zerobrane-studio. All the details to how paths to mobdebug and required modules are configured should still be applicable to your environment.

Why do I get "No process is associated with this object." when calling process.Close() or process.Kill()?

I have a C# program that is launching TShark.exe which is the background equivalent of WireShark. I would like to close all instances that I start. It appears to start just fine, run in the background and log network traffic to a file as it should. However, when I try to close it, I get a "No process is associated with this object." exception.
Here is how I'm starting the processes:
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
Arguments = $"-i {nic} -t ad -w {GenerateLogPath(nic)}",
FileName = "\"C:\\Program Files\\Wireshark\\tshark.exe\"",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
};
WireSharkProcesses.Add(System.Diagnostics.Process.Start(processStartInfo));
I've tried several methods to close/kill these processes. First, I kept a list of all processes that I had started in my app and called the following on them without success:
process.CloseWindow();
process.Close();
process.Kill();
I kept getting the "No process is associated with this object." exception.
So, I used:
var processes = System.Diagnostics.Process.GetProcesses();
And got a list of all processes on my machine and looped through them and attempted to close those who's process name was "tshark" or "dumpcap". I attempted this with .CloseWindow(), .Close(), and .Kill() all of which failed and threw the above exception.
I even went into TaskManager and attempted to END TASK on them. They appeared to be removed, but upon closing and re-opening TaskManager, they magically reappeared. There are also now several instances of "tshark" and "dumpcap" that show up when I call GetProcesses(), but are not in the list of processes that Task Manager shows.
What am I missing here?? Short of rebooting my machine, how do I get these processes to exit? Is this just a wireshark problem, or a general problem with killing processes?
Are you using WinPcap or Npcap? If you're using WinPcap, you could try switching to Npcap and using that instead. See Gerald Comb's comment #32 on the recently closed Wireshark Bug 14701.
By the way, in case you weren't aware, tshark is capable of capturing on more than one interface at a time, so in theory only a single instance is required. I understand that this can sometimes cause reassembly problems though, so if that's what you're trying to avoid or if you just want to keep packets separated by interface, then yes, you'll have to start multiple instances.

Does anyone know how to connect RabbitMQ with COBOL?

Does anyone know how to connect RabbitMQ with COBOL? I tried the documentation in RabbitMQ site but the examples make calls to programs like "RMQ_CONNECT" that don't exists.
From the looks of it, RMQ_CONNECT is not a program, but an entry point in a library. Try using Call "RMQ_CONNECT" and make sure the rabbitMQ library is properly linked for your environment.
Write a c or c# helper exe that takes the payload on the command line and sends it to rabbit, then execute it with a "Call SYSTEM using command-line"
like this:
insert-mongodb-record.
move spaces to command
string "mongo --quiet --eval 'db.norple.insertOne({_id: """my-id""", age: """my-age""", initial:"""my-initial""","
"description:"""trim(my-description)""", nimbus:"""my-nimbus"""})' cobol"
into command
display command
call "SYSTEM" using command end-call
exit paragraph
.

Haxe - Adding an event to process exit?

Haxe porgramming beginner here and I can't seem to find a solution for my problem.
I'm simply running another program on the computer via sys.io.Process.
import sys.io.Process;
import neko.Lib;
class Main
{
static function main()
{
var cProcess = new Process(pClient + sArgs);
}
}
I only want my Haxe program to be running as long as the "cProcess" exists.
So I need some kind of Eventhandler that calls a function when the cProcess is being closed.
Does anyone have an idea how to solve this problem?
Any suggestions welcome!
Thanks!
If all you want to do is wait for the process to complete it's execution
just call exitCode(), it will block until launched process exits.
var cProcess = new Process(pClient + sArgs);
cProcess.exitCode();
trace("Done!");
Mihail's solution is simple and should work.
If you need more on that, you can try asys, which is the asynchronous version of the sys package in Haxe standard library.
var process = new asys.io.Process('your command');
process.exitCode().handle(function(code) trace('process exited with code: $code'));
It also depends on the platform you are running on. If you are running on platforms with async io like nodejs, things should be simple. Otherwise you have to consider threads.