Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open and Closing Programs through Command Line 1

Status
Not open for further replies.

t35li

Programmer
May 28, 2009
12
CA
I'm writing a perl program that basically use command line to open a program, does something with it, and close the program. And this will be in a loop. I have problem with closing the program. Just for an example,

system("notepad.exe");
.
.
(does something with notepad and saves the file to somewhere)
.
.
system("taskkill /im notepad.exe /f");


The notepad opens, but it doesn't close. And when i close it manually by clicking the X button, it says :
ERROR: The process "notepad.exe" not found.

any suggestions?
 
just to make it clear, I'm not trying to read or write to a text file, even though i used notepad as an example.
 
It's waiting for notepad.exe to finish before continuing with your perl script. Why do you need to kill the process, does it not terminate when its job is done?

Anyway, you could achieve what you describe by starting the process in the background, something like this perhaps:

Code:
system('cmd /c "start notepad.exe"');

Annihilannic.
 
If the program you are starting won't finish without some input from the terminal this could be a bit tricky. Can you be a bit more specific about what it does, and whether it produces any output? If it is just something like dir, you shouldn't need to kill it.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
okay, basically the program that I want to run is image creating program, something like photoshop. Except, all I want to do is, Open the program, load an input file, save the output image of the program to somehwere, and close the program. So in the end, I will have a folder of over 200 of the output image files. I want to put htis in a loop so that I dont have to do each one manually.
 
Have you considered using something like Jasc Batchmaster (if I recall the name correctly) instead, i.e. a command-line batch image manipulator.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top