How to start background script in lua - lua

I have a script that's time critical. To speed up things I made a separate script that contains the code that is not time critical. In my main (time critical) script I want to start the non time critical script at the end before it returns nil. How do I start the second script without waiting on it? This without stopping the second script when returning nil in the first script.

You can use io.popen to start a new process (implemented in any language) and read its output when you are ready.

Related

DOORS DXL Show output during run

While my DXL script is running on a module I have it print "." during each loop.
I would like this to show in the output while it running, to reassure the user it isn't frozen since it takes a long time to run.
Currently the DXL windows is blocked from the moment the script starts, and when the script is completely done it prints everything at once.
Is there a way to overcome this?
you could use a GUI, a progress bar or write something to a file.
you could use timer callbacks to update your screen.

Rails Runner hanging with specific job

I have a Rails project and I am trying to run a script using Rails runner. This script runs fine on my local machine, but I am trying to run it on a new EC2 instance that I just set up.
When I run the script, it exhibits some very odd behavior. The first line in the script is a debug statement "Starting". When I say "hang" I mean that "Starting" is never printed.
rails runner Script.run //hangs forever
It is worth mentioning that the purpose of this script is to make several HTTP requests. So, in debugging it, I commented out various lines until I had the maximal program that would actually run.
The only line I needed to comment out is the one that actually called Net::HTTP.request. Then, the script would run, and print all of the debug statements that it was supposed to, but it wouldn't actually function as intended (obviously).
What seems odd to me is that the script will not even print "Starting" when the line that makes the HTTP request is present. The error would make some sense if it got to the HTTP request itself and then hung forever, or at least got some part of the way into the program.
What can cause Rails to behave this way? Any suggestions are appreciated.
Thanks!
I actually made a dumb mistake, but I am going to answer my question for anyone who makes the same mistake in the future.
I forgot to add "$stdout.sync = true" to the config file, so Rails just appeared to be hanging because it was not writing to stdout. When the HTTP request was disabled, it ran fast enough so that I didn't notice the writing was delayed.

How to exit hotkey function and continue the script (AutoHotKey)?

Thanks for reading. :)
Let's give an example of what I say. I press shift+g and I execute one function. In the middle of executing it, I want to stop it by pressing shift+h, then execute another function, and then return the script so as it to stay waiting for another keystroke.
I thought about reloading the program, but I couldn't execute the following commands that way. Or, I could execute another program and reload the first one, but it is getting too complicated.
Any ideas will be greatly appreciated! :)
The easiest way is to put the script in a separate file and run it as an external program. Use #SingleInstance Force to be sure only one copy is running, and if you want to kill it use Process, Close with the PID you can get back from the Run statement.
I do this all the time with long complicated scripts that fail frequently. I mostly do that so if the script fails I just hit the hotkey again to restart. It kills the first instance and restarts. Interrupting a running script is just another special case.
Note that you'll need to run AutoHotkey.exe and pass the name of the script and any parameters. Don't try to run the script itself.
As pointed out the easiest way is to put the script in a separate file and run it as an external program. something like this:
RunWait %A_AhkPath% test1.ahk
Then in test1.apk put ExitApp in a hotkey. like this:
+t::
msgbox killing myself!
Exitapp
very simple!

"not enough storage is available to process this command" after using the start command in a batch file with windows 7

I am creating a batch file that needs to open a second batch script in a separate cmd window. I can use all my code successfully if I use the "call" command instead of "start" but that doesn't launch the script in its own window. I have gotten this error many times in the past and its always related to the start command. I change how I do the process and all works well. Why is the start command causing this error and how can I fix it? Below is a sample of my code.
start "" /w "k:\Bundle Support files\record serial.cmd"
The second batch file opens and completes all tasks except the last one which is
goto :exit
:exit
I have changed the last command in the file several times and it always makes it through the entire batch but the last command that would finish that batch fails with the "not enough storage is available to process this command" error. This happens on multiple machines (varying hardware) and multiple OS's. I have attempted the IRPStackSize fix with no luck. Any suggestions as to why I am getting this error?
Thanks,
Kevin
I have encountered a similar problem and the solution for me was rather strange. It appears that setting the title of the window to nothing ("") causes the error.
So, instead of
start "" /w "k:\Bundle Support files\record serial.cmd"
try
start "Placeholder Name" /w "k:\Bundle Support files\record serial.cmd"
I can't test whether this will work in your case (and I doubt it matters as you're long gone) but hopefully this will help someone experiencing any similar errors.
Replace goto :exit with goto :EOF. Do not define the EOF label (it is predefined).
That's what the START command does when you launch a cmd. If you ran START cmd you wouldn't expect CMD to exit immediately - it stays there ready for use. So you either CALL a cmd file and it will finish, or you START a cmd, and it will not finish - but you can make it finish by using the EXIT command. The issue of the stack overflow was also answered correctly by SEIPIA - instead of using start "" filename.cmd, put something between the quotes to act as the title - that will prevent the stack overflow error.

Powershell: How do I pass a log4net object to a background job?

I may be trying an invalid approach, so I'm open to any suggestions.
I'm running a series of 3 scripts that each do an analysis of websites on an IIS server, and I'm running them against a couple hundred servers. I'm proof-of-concepting doing this as a Start-Job process so I can run in parallel and finish a lot more quickly. These scripts mostly wait around for WMI and the file system to gather and return data, so parallel waiting makes a lot of sense.
But I can't get my jobs to log. I'm piping a data row to the script and trying to send the Log4net $Logger as a parameter, but the new Powershell processes can't do anything with it. Here's what I've tried:
(In the calling script)
$jobs += Start-Job -InputObject $app -FilePath $command -Name $app.Name -ArgumentList $Log
(In the called script)
param ([parameter(Mandatory=$false,ValueFromPipeline=$true)]
$object,
[parameter(Position=0)]
$Logger)
(Result)
Unable to find type [log4net.ThreadContext]: make sure that the assembly containing this type is loaded.
I've tried various flavors of loading the log4net.dll in the called script. That results in:
Method invocation failed because [Deserialized.log4net.Core.LogImpl] doesn't contain a method named 'Info'
I've also tried just instantiating a new $Logger in the called script processes, and that does result in some log action, but not accurately. Of 20 processes, I only get some messages from 9 of them and all messages from none.
Not logging is not an option. The work is complex. Running different logs for each instance of the script might be doable, though it'd be a nasty, nasty nuisance. Mostly, I just figure I'm doing something uninformed.
Each spawned PowerShell process is its own memory space. Nothing is shared between them, so asking log4net to safely manipulate a file system log in multiple spawned jobs is a fail. Database or event log logging handles the safety issues appropriately and resolved this question.

Resources