Okay, so I have a .net exe, and it runs when I type mono myexe.exe. However, if I want to use another command or close the terminal window the app stops executing.
I have tried using mono myexe.exe & and it runs and showing [8] 20078 etc., but once I type something else it shows [8]+ Stopped, and then executes the command I typed in.
Any ideas?
how about nohup mono myexe.exe &
If you want to use & then look into outputting the result to a file.
nohup mono program.exe > program.out &
The right way of doing this would be to create a daemon with your linux distro.
You can also run it as an service using this line of code:
mono-service -l:/tmp/myservice.lock ./ServiceDaemon.exe
where -l:LOCKFILE specifies the file to use for locking. When you look into your lock file, you will see the process id. The process id you can use to kill the service, whenever you need to terminate it.
Source: blog.chudinov.net
Related
When I run my selenium framework it runs as a process. There is no user interface. It runs until it completes or until it encounters an exception that stops the test. Currently, the only way to manually stop the test is to kill the process in Task Manager.
I would like the user to be able to press a key, like escape, to stop the process.
I've only so far been able to find such functions related to a project running in a console
You could create a batchfile with the following contents:
taskkill /F /FI "IMAGENAME eq notepad.exe"
(replace 'notepad.exe' with the correct program name)
When you create a link to that batch-file, you can also specify a 'Shortcut key' to start this batchfile.
Thank you Luuk. To work around I created a batch file that is now included in the build.
I need to execute a WinDbg command through C#. To be more clear, open the WinDbg through C# in background, execute a command in the windbg command line and close the windbg application. Does C# provide any APIs for doing this ??
If you really want the GUI, just use the -c switch to pass a command to the window. An example command line to attach to Calculator and dump the stack:
windbg.exe -pn calc.exe -c "kb"
This leaves Windbg open and attached to calculator, displaying the result of running kb.
If you don't need the Windbg GUI and just need to execute a command to get the output of it, use CDB (the command-line debugger equivalent).
cdb.exe -pn calc.exe -c "kb; qd"
So here, the command in quotes after -c is executed after attaching to the process named (due to -pn) "calc.exe".
In either case, if you instead have the process ID (PID), use -p:
cdb.exe -p 1164 -c "kb; qd"
As for running it from C#, the easiest way is to start a Process and read the console output. See this answer for a ready-to-go solution.
No, C# does not have API to run or control WinDbg.
You can use general purpose Process.Start to launch WinDbg and pass script to it.
You can execute C# code from Windbg command line, and an approach is to write a plugin for Windbg. Not sure this is the approach you're after but if so here is a post how to do.
see:
https://powerdbg.codeplex.com/
it is not C#, but it is >net and may be you will find out an approach
If you are ready to change ะก# to python, see
https://pykd.codeplex.com
And at last, you can use native dlls DbgEng/DbgHlp from your managed code
Naitive debugger engine cannot be used unless you wrap it around c++/cli checkout mdbglib
https://mdbglib.codeplex.com
This is a debugger written such a fashion
You can use ClrMD for C# API
Here is the sample code to get started
C# code snippet on how to use it
// Create Debugger instance and call Execute for any Windbg Command
using (DbgEngine dbg = new DbgEngine(DumpFileName))
{
Console.WriteLine(dbg.Execute(".time"));
Console.WriteLine(dbg.Execute("~"));
Console.WriteLine(dbg.Execute(".sympath"));
}
Simple Debugger to run Windbg Commands and also query .NET CLR Runtime data in C#
https://github.com/sukesh-ak/AutoDebug
Am trying to run "show Desktop.scf" using System.diagnostics.Process.Start() in C#. But the debug line just passes and takes no action.
When I try using Start -> Run, it performs the show desktop action.
Process.Start takes a filename. Why wouldn't this work from the code. I tried in Admin mode too.
Any guidance pls.
Hand in a ProcessStartInfo with UseShellExecute set to true.
This executes the scf in the same way START -> RUN would do.
shell:::{3080F90D-D7AD-11D9-BD98-0000947B0257}
in Start -> Run does the same as running the .scf
I was making an AutoHotKey script when i encountered the same problem.
But when i replaced the path to .scf with the above code it worked like a charm.
i made a windows service & add project installer.in which only contain this code.
System.Diagnostics.Process.Start(#"C:\Windows\system32\notepad.exe"); inside the timer tick event & interval is 60 sec.i just wanted to try to run Windows service.
1st-serviceProcessInstaller1 i have been changed its account setting as local system.
2nd-serviceInstaller1 in this case i have been changed its start up type as Automatic.
then i create a setup add another project then right click add project output then add primary output then press ok.
then go to Right click on project->view->custom Action->right click on Install->Add custom Action->select Application folder & add primary output.the same thing done for all the remaining options like commit,rollback,uninstall.
after that i build the setup it build succesfully then i install the setup it installed properly into program file n create one .exe file n one Instalfile.
but problem is that when i search the service into "services.msc" the service is not there.
means service is not showing there.i tried but not getting the ans.plz help me to solve this problem.
Not the answer to your original question, but
Starting an application with a GUI from a service is a bad idea (tm) and won't work in the majority of cases
Check what kind of Timer you use. .Net provides 3 Timer classes, not all of them work in a service (because they depend on a window's message loop, iirc)
To test any service: Why don't you go for the installutil binary first (bypassing the setup project)? You find it in your framework directory, for example in "C:\Windows\Microsoft.NET\Framework\v2.0.50727".
I'd suggest trying to install the assembly manually to see if you get any kind of error message.
Just open a Visual Studio command prompt and run InstallUtil.exe [YourService].exe. At least you'll know if it installed properly.
Even better option is to use the command line tool sc.exe
Try "sc create /?" on command line and see its options.
You can then use "sc start " , "sc stop " & "sc query " to control service. You can use sc.exe to send custom command to the service. Check windows event log for errors related to service installation. It may be .Net version used to create it is not on target machine.
I would post a snippet, but I honestly have no idea what part of my code could possibly be doing this. The program is sizable, I don't want to make you all wade through it. What kinds of things could possibly be the cause of this? Everything works perfectly when called from the command prompt: "readoo.exe". But when I click the exe in its file. . . "readoo.exe has encountered a problem and needs to close. . ."
this is intended to eventually be a scheduled task -> i'm worried, will it work?
i've never debugged, all i've ever used is notepad. I am learning, and feel that this strengthens my understanding of a project.
it crashes nearly immediately. there are no shortcuts, though the file paths are relative.
trying this method: shortcut -> properties -> shortcut -> Start In. I don't have a "shortcut" option
my program reads log files, parses, and creates 4 new files based on the found content
Microsoft Error Report says file not found. But how can this be? the files are there, albeit relative.
Take a copy of your project, and then start hacking bits out of it. When it no longer crashes, you've removed the bit causing the problem.
At what point does it fail when you double-click on it? Immediately, or only when you take a certain action?
You could also add a lot of logging to it, which could indicate where the problem is too.
This is probably looking for a dll that it can't find or is finding a different version from what it wants.
You could try Process Monitor or Process Explorer from sysinternals to see what dlls it loads when it does work and where it finds them.
Try putting a System.Diagnostics.Debugger.Break()call as the first thing in Main() and you'll be asked to attach a debugger - this should definitely show you what is different betweent the 2 invocations.
I would start with identifying what is different in the two methods of execution. Is there a shortcut modifying anything?
The starting directory?
The execution account?
command line arguments?
There are 2 things that it could be:
The current directory could be different when you click on the program or run from the command prompt.
The settings and path could be different when you click on the programe you are using the standard command prompt, are you opening the visual studio command prompt when you run the program from the prompt.
If your application relies on some file that should be on the same path of that exe, that can occurr.
You will have to change the properties of the exe (or shortcut to the exe) to "Start In" the directory where your exe is. For a shortcut, right click on the shortcut -> properties -> shortcut -> Start In.
I guess that is what I think could be the cause.
EDIT: Add a Console.ReadLine towards the end of your code to make it pause for you to see any exception thrown. That should help when you run it using windows explorer.
Put a try/catch around your code and output the exception message to the console in the catch block. That should give you some clues.