Observing and running a program when another program is ran - windows

Lets say I have One.exe and Two.exe. I would like to have a script that will run Two.exe as soon as One.exe is ran and finished loading.
Now, I was wondering what is the better way to do it:
have a script that will be started along with Windows and just sit
quietly in the background, listening for when One.exe will get
started and loaded.
Somehow attach a script to One.exe, so when it runs, the script runs
Two.exe
some other ideas that I don't have yet.
I haven't done any batch scripts yet, so I wanted get into the right way so I know what to search and read about.
Is my idea possible to get realized at all?

Add a simple delay after one.exe is launched with ping or timeout commands.

Related

Get stdout from an idle background application in Windows

I have an ffmpeg.exe process that appears to be hung - it hasn't done anything for several days. It was started by exec() in PHP, so is running in the background and has no window.
I would like to know what caused it to stop/hang.
Is there anyway to get what it has written to stdout?
I don't think I understand you correctly, but I'll try.
If you wanna see its output, you can hook its output functions via IAT/inline hooking and redirect it to a file or something.
However, I think you just wanna see what it is doing. In that case I suggest you to use "Procmon" from the "Sysinternals Suit".

How can I kill proces in Win2008R2 whenever it starts?

I have problem in my Windows2008R2 server, wich I use it like print server. Driver from Canon, CNABGSWK.EXE start in random times and fill my processor on 100% and all print jobs stopped.
Any idea how to stop/fix this?
Maybe with batch script, which always run in background and kill this process when it starts?
tnx
The only way to do this would be to either make a batch script to check if the process is running every X amount of seconds/minutes and kill it, or you can rename the file to something like CNABGSWK.EXE.BAK.
Some other Stack Overflow links to help you if you're making the script:
How to stop process from .BAT file?
How to check if a process is running via a batch script

Livecode standalone program takes 30 seconds to load

I've run into an issue with a program I created using Livecode, and now I'm looking for some help from the experts. My Google-fu is strong, yet the answer eludes me...
So here's the deal. I made a very basic note-taking program for Windows only, using very noob skills. I've been using it daily for work for the past month at least. It functions exactly as it should, except for these few things that don't make sense:
When loading the program, it takes 25-30 seconds to load. Not convenient considering it's pretty basic; one button and 5-6 text input fields, with the same number of label fields. And one background. The button just clears the text input fields.
I started to notice a problem when I went to create a batch file to load all my work programs. When the program is loaded thru Command Prompt, if I close CMD it will close the program too. I tried the same using Powershell, and it still closes as soon as the Powershell window closes. Really really strange.
I managed to find another standalone program made with Livecode, downloaded it and tested the CMD command to see if the same thing happened. It didn't, that program loaded instantly and it is ENORMOUS. It also didn't close when I closed the CMD window. I even tried this: opened my program and the downloaded program using the same CMD session, and when I closed CMD, my program closed but the downloaded one did not.
Then, I downloaded the source code for the program that was working correctly. I created a standalone for it, and tried to open that. It acts the same way as my note program does.
I don't get it. It's got to be something in my Standalone Application Settings considering what happened in the last step I mentioned, and I've been over and over those settings for hours, but I just don't have the knowledge of LC to know what to look for. I've scoured the web looking for answers to this, but it seems to be just me having this issue (story of my life, lol).
I'll be happy to post any codes, scripts, or files needed, please let me know. I just don't know which things to post =P
Any suggestions are very much appreciated!! Thank you. =)
If you call the program from the prompt directly, e.g. using
C:\program files (x86)\your_standalone.exe
the app is treated as a command line app. I have also noticed that a LiveCode app can sometimes close if the invoking command line prompt is closed, while it may sometimes continue to run. Perhaps the handling of the relaunch message has to do with it, since this message basically handles commands from the command line.
If you want the command line process to finish independently from the invoked LiveCode application, you can use the start command:
start "" "C:\program files (x86)\your_standalone.exe"
don't have enough info to be able to tell what your issue is. But that much of a delay is not usual for LiveCode apps so something is definitely wrong. How long does your app take to load if you open the stackfile in the IDE?
Not sure what StackOverflow allows but if you could upload your scripts and if possible stackfile that will give us more to go on
This has nothing to do with Windows, Batchfiles, or CMD.
CMD can workaround your problem, if it's a GUI program. See Start command, and read the help as it explains the starting behaviour of CMD and CMD's Start.
Explorer has different rules. Anything else that starts programs call CreateProcessExW which has it's own rules.

Run a process each time a new file is created in a directory in linux

I'm developing an app. The operating system I'm using is linux. I need to run if possible a ruby script on the file created in the directory. I need to keep this script always running. The first thing I thought about is inotify:
The inotify API provides a mechanism for monitoring file system events. Inotify can be used to monitor individual files, or to monitor directories.
It's exactly what I need, then I found "rb-inotify", a wrapper fir inotify.
Do you think there is a better way of doing what I need than using inotify? Also, I really don't understand the way that I have to use rb-inotify.
I just create, for example, a rb file with:
notifier = INotify::Notifier.new
notifier.watch("directory/to/check",:create) do |event|
#do task with event.name file
end
notifier.run
Then I just ruby myRBNotifier.rb, and it will stay looping for ever. How do I stop it? Any idea? Is this a good approach?
I'd recommend looking at god. It's designed for this sort of task, and makes it pretty easy to build a monitoring system for background and daemon apps.
As for the main code itself, inotify isn't cross-platform, so if you have a possibility you'll need to run on Windows or Mac OS then you'll need a different solution. It's not too hard to write a little piece of code that checks your target directory periodically for a change. If you need to know what changed, read and cache the directory entries then compare them the next time your code runs. Use sleep between runs to wait some period of time before looping.
The old-school method of doing similar things is to use cron to fire off a job at regular intervals. That job can be your script that checks whether the file list changed by comparing it to the cached version, then acting as needed if something is different.
Just run your script in the background with
ruby myRBNotifier.rb &
When you need to stop it, find the process id and use kill on it:
ps ux
kill [whatever pid your process gets from the OS]
Does that answer your question?
If you're running on a mac/unix machine, look at the launchctl man page. You can set up a process to run and execute a ruby script whenever a file changes. It's highly configurable.

Remotely Executing an Independent .exe on an Apache Server [CGI]

I have an executable program I've created which is a server. I would like to be able to start and stop instances of this program on a Windows Server 2008 machine via the website the same machine hosts.
The functionality I'm hoping to achieve is: from anywhere I can access my website to start and stop instances of the server code instead of constantly Remote Desktop-ing into it just to start/stop it.
I've tried using Perl, but when I run the code it looks like it prints out some of the information the program does (so it's working) but then seems to stop. Whereas I would like it to start an instance of the program as its own process.
Perl:
#!C:/Perl64/bin/perl.exe
print "Content-type: text/plain\n\n";
exec('C:\file.exe');
I'm not sure what language I should be using or if there are completely other, better ways of achieving my goal. Thanks!
exec is the wrong choice, and so are threads. Simply start the process in the background. You did not say how you would normally stop the server. If it has its own command for stopping, the same as for starting applies; else kill the process.

Resources