Retrieving exit code in ProcessExit handler? - c++-cli

I'm writing a little C++/CLI application that calls a lot of libraries. Inside some of them there is at least one exit(xyz) and I catch it by handling AppDomain.ProcessExit(). Works fine. Since the call to exit(...) has already been done, I would like to retrieve the exit code passed to this function.
My problem is that it seems that the exit code is not available before the complete exit of the process and, of course, in my handler, the process is not "completely" terminated/exited. For example, I tried:
int ec = System::Diagnostics::Process:GetCurrentProcess()->ExitCode;
But I got an exception. Also it seems that the API Win32 GetExitCodeProcess() will return me a STILL_ACTIVE error??? I hope this value is registered/accessible somewhere?
Any idea? I'm running on Win 7 and Win 10. Thanks in advance for your help.

I have done this using a batch file before.
I create a file called runprogram.cmd(you can create your own name if desired) and place the following in it: -
#echo off
"programname.exe"
echo %errorlevel%
#echo on
pause
replace programname.exe with your exe's name.
double click on the file to run it.

System::Environment::ExitCode;
Process, AppDomain, Environment... I missed this one! I hope my question/answer will help someone some day!

Related

Asterisk dial command return dialed number

I'm looking for a variable that can tell me which number 'won' the call on a multi-target Dial command.
Example:
Dial(SIP/1000&SIP/1001&SIP/1002,30)
Set(the_unlucky_winner=${...})
I'm not getting anything from the ${DIALEDPEERx} variables. Sounds like these vars are broken but I don't know if this is what I should be using.
Ancient version 1.2.14 deployed at this site. All clients are SIP
Thanks anyone
Only realistic way do that - cal via Local channle like freepbx do(check freepbx.org source) or use Macro on answer(i am afraid not work in 1.2)
Parse the contents of the CDR record for the file. One of the fields is dstchannel which will hold a value like SIP/1002-9786b0b0.
Also keep in mind that the call variable stack is wiped on hangup, unless you have an "h" (hangup) extension defined for the context. So, you can most easily handle your post-call processing there.
Further Reading:
http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/asterisk-SysAdmin-SECT-1.html
Please Note:
if this answer turns out to solve your problem, please "accept" it for the benefit of others trying to solve the same problem later
Hi all I have a solution to this problem. It is working fine for both normal dial and multi target dial.
In dialstring add a macro, here I am adding "followme" macro.
M(followme)
$agi->exec("dial", "SIP/6001#sip.example.com&SIP/6002#sip.example.com,rtTgM(followme)");
Then after call is answered it ll go to context
[macro-followme]
In this context you write one script to get the connected calls information by
$dstchannel=$agi->get_variable("DIALEDPEERNUMBER");
The way I managed to do it is as follows
Dial(SIP/1000&SIP/1001&SIP/1002,30,M(whoanswered))
[macro-whoanswered]
exten => s,1,NoOp(${CHANNEL})
You will see that the actual extension that answered is containes in ${CHANNEL}
If 1001 answered the channel will be something like SIP/1001-00017cf1
Just use the CUT command to cut it by / and -

Lua, Altered Program Flow When Rquired File isn't there

I want to test to see if a require'd file is there or not.
At the present, when I execute this command in Lua:
require "File_That_May_or_May_Not_Be_There.inc"
All is well if he's there. If not, my script is dead on the spot.
Is there a way for me to recover from this ?
I looked HERE on the Lua.Org site and HERE on StackOverflow and haven't seen this answered.
Is there a way to do something like this ?...
if (this_exists("That_File")) then
require "That_File"
else
print "Your file does not exist"
end
I'm trying to let the user have a little better idea of what went wrong, and why.
Use pcall.
local ok, mod = pcall(require, "That_File")
If you don't need to use require, which looks for modules in several locations, you can use
local f,e=loadfile(filename)
if f==nil then
print(e)
else
f()
end

SMJobRemove succeeds, but plist and helper tool not deleted

I'm trying to remove a privileged helper tool installed via SMJobBless, I'm getting a positive return value and no errors, yet the files at /Library/PrivilegedTools and /Library/LaunchDaemons are not deleted. Do I have to delete these files myself?
From the documentation I read:
Return Value true if the job was removed successfully, otherwise
false.
I'm calling the following to remove the job:
result = SMJobRemove(kSMDomainSystemLaunchd, (__bridge CFStringRef)label, _authRef, YES, &errorCF);
Thanks jatoben, that thread had the answer I was looking for.
As suspected you do have to remove the files yourself or use the following: (Taken from Apple dev forums:)
SMJobRemove is the equivalent of "launchctl remove". That is, it
removes the job from launchd but has no effect on the disk at all.
Thus the job will get reloaded the next time you start up. To get
around that you have to either remove the plist yourself or by
fork/exec'ing "launchctl unload -w".
Have you seen https://github.com/brenwell/SMJobBless-Demo/blob/master/Uninstall.sh? It was very helpful for me.

Searching the registry for a string in vb.net?

I am trying to do a query on the registry for uninstallation of a program but dont know where to start.
The structure would be like so:
If {123-456-789} exisits in registry then run
Msi.exe /x {123-456-789}
Otherwise run
Msi.exe /x {987-654-321}
Does anyone have any pointers on how to do this?
Start from here :-)
"Reading from and Writing to the Registry"
http://msdn.microsoft.com/en-us/library/85t3c3hf%28v=vs.71%29.aspx
Check how RegistryKey / Registry / RegistryHive class works,
Take a starting point (in the registry), then enumerate all the key/subkey/value, and compare the string/value found to check if they are what you are looking for.
https://superuser.com/questions/65714/how-can-i-search-the-windows-registry-with-regular-expressions googling for this - I found this article.. the exporting it idea might work for you?
Also this guy seems to do what you need.
http://www.vbdotnetforums.com/vb-net-general-discussion/38567-regex-visual-basic-net-2005-case-insensitive-registry-search.html

getting result from a function running "deferToThread"

I have recently started working on twisted not much familiar with its functions.I have a problem related to "deferToThread" method...my code is here to use this method
from twisted.internet.threads import deferToThread
from twisted.internet import reactor
results=[]
class Tool(object):
def exectool(self,tool):
# print "Test Class Exec tool running..........."
exec tool
return
def getResult(self,tool):
return results.append(deferToThread(self.exectool, tool))
to=Tool()
to.getResult(tools)
f=open(temp).read()
obj_tool=compile(f, 'a_filename', 'exec')
[ at 0x8ce7020, file "a_filename", line 1>, at 0x8cd4e30, file "a_filename", line 2>]
I am passing tools one by one in getResults() method it executs successfully & prints the results what script written in the file objects.
I have to store the result of tools executing in some variable so that I can save it in database.How to achieve this cause when i call re=to.getResult(tools) and print "re" it prints none.
I HAVE TO STORE ITS RESULTS IN DATABASE? IS THERE SOMETHING I CAN DO?
thanx in advance
There are two problems here.
First, deferToThread will not work if you never start the reactor. Hopefully this code snippet was actually extracted from a larger Twisted-using application where the reactor is running, so that won't be an actual problem for you. But you shouldn't expect this snippet to work unless you add a reactor.run() call to it.
Second, deferToThread returns a Deferred. The Deferred fires with the result of the callable you passed in. This is covered in the API documentation. Many APIs in Twisted return a Deferred, so you might want to read the documentation covering them. Once you understand how they work and how to use them, lots of things should be quite a bit easier.