Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Batch commands - Send input to running .exe?

Author
Message
SpyDaniel
18
Years of Service
User Offline
Joined: 4th Feb 2006
Location: United Kingdom
Posted: 7th Mar 2014 00:22
I am trying to set up a simple batch file that will wait for a certain amount of time, then send input to a running .exe without any user intervention.

Example:

timeout 600
[send "save" to example.exe]
timeout 5
[send "stop" to example.exe]

^ What would the actual batch command be for my send command?



BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 7th Mar 2014 03:09
I'm not sure there is a way to do this directly in the prompt. You'll probably have to write a program that will run some code to do it.

The easy way might be to create a file and have example.exe watch the file and read commands from it. You could probably even write straight into the file using batch commands. There are probably more complicated but more correct things you could do like pipes or networking.

mr_d
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 7th Mar 2014 07:19
I haven't used it myself, but from it's description, it should do exactly what you want it to do. link.

or, if you're not stuck on using batch files only, then the option I'd go with would be this - you know exactly what's happening as you control it and nothing is hidden.

nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 7th Mar 2014 08:08
That first link is interesting. Although I would've suggested scripting too, this other piece of software , Sendkeys.NET, looks fun to tinker with. Nice find!

ver 7.5 /// int 145 /// str 45 /// dex 85 /// end 200 /// mat 3
SpyDaniel
18
Years of Service
User Offline
Joined: 4th Feb 2006
Location: United Kingdom
Posted: 7th Mar 2014 13:09
Sendkeys looks like what I need, but I'm unsure how to get it to pick an active window, as I would have multiple promts open.

Then comes another issue, I might be running two programs, but both have a promt that simply says C:\example\example.exe in the title. I have tried changing the title, but it just opens up the program in a new promt from the batch file with a path to the program as the title. Can I change this?

bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 7th Mar 2014 13:38
I have no doubt qb64 could do this but in a much better and cleaner way. Do you need a bat file?

mr_d
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 7th Mar 2014 13:43
Yeah, not sure about that first issue - it may not be possible to do with a batch file only, although it is very simple to do with scripting; either vbscript, or autohotkey/autoit.

When you say you've trieed changing the title, I assume you meant that you've used the command: start "window1" ... and that it's your program that actually opens up another command prompt.

If that the case, then there isn't very much you can do (easily) - I believe it is possible to change window titles after they'vee been opened using some native windows API calls, but this would be a little messy and not easy.

The easiest solution I can see (if it's possible for what you want), is to change the name of ne of the executable programs, s that it opens the command prompt with it's own name.

SpyDaniel
18
Years of Service
User Offline
Joined: 4th Feb 2006
Location: United Kingdom
Posted: 7th Mar 2014 14:50
If it makes things easier, I'm trying to automate things for a minecraft server. I wanted some thing to send a command to the server, for example, every 60 minutes.

So like:

timeout 3000
save-all

mr_d
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 7th Mar 2014 16:38
I'm not familiar with a minecraft server, but if it's running on a normal windows machine, can't you just use the standard windows scheduler to create a task that runs periodically to do what you want? If not then the second idea is to see if it has built in functionality or an API to do this easily.
The last option is to go with the scripting path as batch files are relatively limited to what they can achieve compared with the other scripting choices.

Like I said, I'm not really up to speed with minecraft (I'm one of the few that hasn't played it) or it's server, but if you need any further help, then I can see what can be done if you can provide me with an idea of what want achieved and the provided tools available.

e.g. if you have the details of the program i.e. the parameters it accepts and the commands able to be used, etc. then I may be able to knock something up for you.

SpyDaniel
18
Years of Service
User Offline
Joined: 4th Feb 2006
Location: United Kingdom
Posted: 7th Mar 2014 21:55
@mr_d

I'll take you up on that if I can't get any of the other suggested things to work.

I know there are programs to do what I want, but I have my server set up already and these programs are used before one is up, in which I'm not sure how they work on importing a server to monitor.

easter bunny
11
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 8th Mar 2014 08:12
You could simply create a file in a prespecified directory with the data you want.
The exe can then check regularly for the file, and if it exists, grab the data and delete it

thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 9th Mar 2014 17:22
@SpyDaniel

What features in particular are you looking to implement on the minecraft server? If you're trying to create auto-saving or something similar, it might be easier to just use a server plugin rather than a batch file.

nonZero
12
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 10th Mar 2014 08:38
I'm starting to think about simplicity by not having too many layers since too many layers creates potential issues. So, if possible, a native binary would be best. Does MC not have some sdk to build apps for servers with?

ver 7.5 /// int 145 /// str 45 /// dex 85 /// end 200 /// mat 3
SpyDaniel
18
Years of Service
User Offline
Joined: 4th Feb 2006
Location: United Kingdom
Posted: 10th Mar 2014 12:55
I basically wanted the server to save, then have the batch file stop the server and then restart the computer. I can't program either, just basic scripting.

I don't know if there is a sdk, but I think you just code from scratch, no easy way round it.

thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 10th Mar 2014 21:27 Edited at: 10th Mar 2014 21:28
How I would go about it:

1) Download the Bukkit server mod. This is probably something you want anyway.
2) Download this bukkit plugin: http://dev.bukkit.org/bukkit-plugins/simple_restart/. Turn off "auto-restart" in the plugin config and set up your desired time period.

At this point you have a server that has scheduled shutdowns. Perfect. Now, it's really easy to accomplish the second part of your request - restarting the computer. Since the Bukkit server already runs out of a batch file, usually called "craftbukkit.bat", all you have to do is modify that file.

3) Add "shutdown.exe /r /t 00" to the last line of craftbukkit.bat. This command should restart your computer as fast as possible. Other commands include /s to shutdown, and /h to hibernate. the number after /t is the delay in seconds before shutdown.
4) Add a shortcut to "craftbukkit.bat" in your startup directory so the batch file runs when you restart.

Just curious, is there a reason for completely restarting the computer?

SpyDaniel
18
Years of Service
User Offline
Joined: 4th Feb 2006
Location: United Kingdom
Posted: 10th Mar 2014 22:09
I want to completely flush the ram of it's data and my thinking is that it will keep the server running smoothly if it gets a complete restart.

The only thing is, I am running a forge server, in which I am not sure how I can get bukkit to work with it, as I need to start the forge server up first and using bukkit requires the bukkit server to start first I think.

thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 11th Mar 2014 01:09
For a forge plugin that does the same stuff as bukkit, you could try using this plugin although its outdated: http://www.minecraftforum.net/topic/1576422-172-auto-shutdown-070-forgeserver/ I'm pretty sure there is also a plugin set called ForgeEssentials that might have similar features.

Login to post a reply

Server time is: 2024-05-04 09:08:09
Your offset time is: 2024-05-04 09:08:09