mIRC Home    About    Download    Register    News    Help

Print Thread
Sending and Receiving from cmd prompt #135888 19/11/05 01:50 AM
Joined: Apr 2005
Posts: 12
M
MrBugman Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Apr 2005
Posts: 12
Hey all. I'm writing a script where I need to be able to read the output from a windows command prompt, as well as send commands to that prompt. (cmd.exe)

I've tried stdio.dll which read it, but crashed when sending. Also tried mConsole.dll which I liked very much except that it also crashes mirc.exe when I try to use it. Are there other dlls or other ways of doing this?

Any help much appreciated, thanks!
- MrBugman

Re: Sending and Receiving from cmd prompt #135889 19/11/05 02:07 AM
Joined: Apr 2005
Posts: 12
M
MrBugman Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Apr 2005
Posts: 12
I suppose another way of dealing with this would be to fix the crash error. Maybe someone knows how to avoid it.

Using Server 2003 with mIRC 6.16 I get this error when using mConsole.dll:

Event Type: Error
Event Source: Application Error
Event Category: (100)
Event ID: 1000
Date: 11/18/2005
Time: 6:36:43 PM
User: N/A
Computer: SURGEAV-SERV
Description:
Faulting application mirc.exe, version 6.1.6.0, faulting module user32.dll, version 5.2.3790.1830, fault address 0x00007eac.

frown
- MrBugman

Re: Sending and Receiving from cmd prompt #135890 19/11/05 09:00 AM
Joined: Dec 2004
Posts: 81
N
nycdiesel Offline
Babel fish
Offline
Babel fish
N
Joined: Dec 2004
Posts: 81
I would be interested in knowing as well. I too have tried both dlls with no luck. I thought may be a COM approach to this. Though I don't know much about COM, lol.

Re: Sending and Receiving from cmd prompt #135891 19/11/05 01:25 PM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
might be talking out of a hole here, but i remember something from why back in WFWG days, that allowed you to send and recieive the output of a dos session, I think it was something to do with redirecting CON (console input and output) to a file?, i think your program then just read and wrote to that file(s). If you dont have any luck I could go search for it, but its been a long time, might have only worked when it was win9x rather than the WinnT that everyone (almost everyone) is on now.

Re: Sending and Receiving from cmd prompt #135892 19/11/05 01:42 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
I can do it with COM, but have no time to show you how at this time. When I get home tonight (that's in 9 hours) I'll see what we can come up with for you.


Gone.
Re: Sending and Receiving from cmd prompt #135893 19/11/05 07:04 PM
Joined: Dec 2004
Posts: 81
N
nycdiesel Offline
Babel fish
Offline
Babel fish
N
Joined: Dec 2004
Posts: 81
I figured you would be the one smile I tried helping him out and couldn't figure it out, lol. Thanks FiberOptics.

Re: Sending and Receiving from cmd prompt #135894 19/11/05 11:32 PM
Joined: Apr 2005
Posts: 12
M
MrBugman Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Apr 2005
Posts: 12
That would be awesome cool

Also, many thanks to nycdiesel for working with me on the dlls for a few hours. smile

I'll look into the other redirect idea, thanks for that too.

- MrBugman

Re: Sending and Receiving from cmd prompt #135895 19/11/05 11:41 PM
Joined: Apr 2005
Posts: 12
M
MrBugman Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Apr 2005
Posts: 12
Quote:
might be talking out of a hole here, but i remember something from why back in WFWG days, that allowed you to send and recieive the output of a dos session, I think it was something to do with redirecting CON (console input and output) to a file?, i think your program then just read and wrote to that file(s). If you dont have any luck I could go search for it, but its been a long time, might have only worked when it was win9x rather than the WinnT that everyone (almost everyone) is on now.


http://www.glue.umd.edu/~nsw/enpm808c/dos.htm#Redirect
Reading through the redirect section this sounds promising, I'd have to play with it to see how it really works, appreciate the idea. =)

- MrBugman

Re: Sending and Receiving from cmd prompt #135896 20/11/05 12:52 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
This will initiate a command console (hidden) that will execute the command that you specified, and will signal the event "cmd" when all output from your command has been received. The output is stored in file cmd.txt. Btw, you should have just said what you wanted to do exactly (what commands are you trying to perform?), because if this was for let's say to redirect output from netstat.exe or ping.exe etc you dont' need the command prompt for that.

Code:
alias cmd {
  if (!$0) return
  var %wsh = wsh $+ $ticks 
  .comopen %wsh wscript.shell
  .comclose %wsh $com(%wsh,run,1,bstr*,% $+ comspec% /c $1- >cmd.txt,uint,0,bool,true)
  .signal cmd $1-
}
 [color:red]  [/color] 
on *:signal:cmd:{
  echo -a Finished executing command: $1-
}


The reason for the signal is that the alias /cmd will be halted until all the output is returned, so the code after the line that says .comclose (in our case signal) could be executed a few seconds after you issued /cmd, since it waits.


Gone.
Re: Sending and Receiving from cmd prompt #135897 20/11/05 01:21 AM
Joined: Apr 2005
Posts: 12
M
MrBugman Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Apr 2005
Posts: 12
I'm using this for a game server, collecting all of the connects and player messages from the prompt of the dedicated server to display them in a script. So the connection is constant, that seems to be the challenge here.

- MrBugman

Re: Sending and Receiving from cmd prompt #135898 20/11/05 01:23 AM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Why don't you just use sockets then to connect to the gameserver, that will make life easier. You should have said this from the start, preventing others from doing unnecessary thinking/spending time. If you want serious help, you're gonna have to stop being so vague, I still don't really know anything of what your script should do. What kind of commands do you want to execute from the command prompt, let's start with that. "collecting all of the connects and player messages..." doesn't mean anything to me.

Btw, it's in theory possible to have a constant connection to a command prompt,initiated with wscript.shell's exec method, but in practice it crashes your mirc when sending commands through it, or even when reading from it in certain occasions. Not usable.


Gone.
Re: Sending and Receiving from cmd prompt #135899 20/11/05 03:05 AM
Joined: Apr 2005
Posts: 12
M
MrBugman Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Apr 2005
Posts: 12
I'm sorry for being vague, was just trying to make it simple.

I'm running a Tribes 1 dedicated server, with several bots on the same machine local to the game server. Later I'd like to use this same method with other game types. I'd like to be able to collect all of the server output to parse it to echo into an IRC channel used by the group running these game servers.

Users in the game can send text to IRC and users in the IRC channel can send messages to users inside the game. I'd also like to display Player Connections/Disconnections, map changes, etc all shown in the command prompt of the dedicated game server.

I wasn't aware sockets could be used to send directly to the console or read from it?

- MrBugman

Re: Sending and Receiving from cmd prompt #135900 20/11/05 04:20 AM
Joined: Sep 2003
Posts: 4,230
D
DaveC Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
http://www.glue.umd.edu/~nsw/enpm808c/dos.htm#Redirect
Reading through the redirect section this sounds promising, I'd have to play with it to see how it really works, appreciate the idea. =)


No it wasnt that, althought if thats all you needed, Ie running a dos app and redirectiing output and input to/from files then sure use the > & < redirectors. But i think u said interactivily send commands to the dos window (and from that i assume u mean the application running in it).


What i was meaning was this
from COMMAND.COM /?

COMMAND [[drive:]path] [device] [/E:nnnnn] [/P] [/C string] [/MSG]
[drive:]path Specifies the directory containing COMMAND.COM file.
device Specifies the device to use for command input and output.

the device can be like COM1: etc, however from memory what i had done was a first load a small program that created a COM5 (i think) and then you called COMMAND.COM COM5:
The small program constantly monitored com5in.txt for things to type and output to com5out.txt. very simple and very usable. However i cant remebe4r what the program was called or if it was even COM5 might have been like a name u could specificy even. It was a small dos util (freeware) So i couldnt even say if it would work under Xp. Did a good job under WFWg and 95 from memory.

PS: I think FiberOptics might be on a better path hear to a solution.

Re: Sending and Receiving from cmd prompt #135901 20/11/05 11:17 PM
Joined: Apr 2005
Posts: 12
M
MrBugman Offline OP
Pikka bird
OP Offline
Pikka bird
M
Joined: Apr 2005
Posts: 12
I played with this stuff for a few more hours. The problem I'm having is that the dedicated server console always opens in a new prompt when I start the server, so anything I try to change the input/output for only changes for the prompt that I executed the server from, which is not the newly created prompt with the echoes. frown

Someone else has suggested telnet to me, and I may be getting somewhere with that, as Tribes1 has a telnet plugin I've installed.

Really have appreciated the help I've gotten. Want to appollogize to FiberOptics, my intent was to use the prompt reading for more than just game servers, so I wanted a solution that worked with anything that echoes to cmd.exe, which I now see is not the way to handle that when using mIRC scripting.

I'll post again and let you all know how telnet is going, so far I've been able to read general messages from the dedicated server, and it looks like I can edit the telnet code to return everything else I need.

- MrBugman

Re: Sending and Receiving from cmd prompt #135902 05/01/06 05:09 PM
Joined: Jun 2003
Posts: 15
Z
ZeBoxx Offline
Pikka bird
Offline
Pikka bird
Z
Joined: Jun 2003
Posts: 15
Just wanted to give a big "Thanks!" to you, FiberOPtics, for the script posted.
In modified form it functions excellent to essentially halt processing of a script while the called command is being run.

Specifically, I needed this because I'm launching an external batch file to create a folder (I'm going to guess I could actually do this with the shell scripting stuff as well, but that's for later investigation) - and need to check whether the folder was successfully created.

//echo -s $ticks | /run mybat.bat | /echo -s $isdir(c:\thedir\) | //echo -s $ticks
would execute in 1 go, and $isdir would return $false , as the dir would not exist yet.

//echo -s $ticks | /cmd mybat.bat | /echo -s $isdir(c:\thedir\) | //echo -s $ticks
waits at the /cmd , and $isdir returns $true (assuming the dir was actually created(!)) when it should smile

Thanks again!


__________
ZeBoxx
ŻŻŻŻŻŻŻŻŻŻ