views:

152

answers:

2

Hello,

I'm working on a project in which I'd like to be able to turn lights on and off in the Duke Smart Home via a high frequency chirp. The lighting system is called Clipsal Square-D and the program that gives a user access to the lighting controls is called CGate. I was planning on doing some signal processing in Matlab, then create a batch file from Matlab to interact with Cgate. Cgate is a proprietary Java app that, if run from a DOS command line, opens up another window that physically looks like the DOS command prompt. I have a batch file that can check to see if Cgate is running and if not, open it.

But what I can't figure out how to do is actually run commands in the Cgate program from the batch file and likewise, take the response from Cgate. An example of such a command is "noop," which should return "200 OK."

Any help would be much appreciated! Thank you very much in advance :)

(here's my existing batch file by the way)

@ECHO off

goto checkIfOpen

:checkIfOpen

REM pv finds all open processes and puts it in result.txt
%SystemRoot%\pv\pv.exe
%SystemRoot%\pv\pv.exe > result.txt

REM if result has the word notepad in it then notepad is running
REM if not then it opens notepad
FIND "notepad.exe" result.txt
IF ERRORLEVEL 1 START %SystemRoot%\system32\Clipsal\C-Gate2\cgate.exe

goto end

:end
A: 

I don't know how to do this on Windows, but on UNIX, there is a program called expect that is designed for such a task. If you install Cygwin, you should be able to use the expect utility on Windows.

Michael Aaron Safyan
You can find a non-Cygwin version herehttp://sourceforge.net/projects/expect/
Romain Hippeau
I downloaded expect but I can't understand how to incorporate it into a batch file - do you have any more tips on syntax and the like?
Justine
I looked more into things and found out that "cygwin's Expect works fine under Cygwin as long as what you're expect'ing upon is a cygwin application. It does not work with normal/native Win32 console applications." So I tried using ActiveState's version but am stumped.
Justine
A: 

You're calling start cgate.exe, which will cause cgate.exe to be launched in a new window. First off, you probably want to run cgate in the same window, which means you should drop the start.

Secondly, you can use shell redirection to pass commands to the STDIN of cgate from a text file, like so:

cgate.exe < commands.txt

This will probably work, but it might not, depending on how cgate.exe is actually expected to receive its data.

If you want to have two-way communication, where you send in data, get the response, then send in more data depending on what the response was, you'll have to use something other than a batch file. Most scripting languages (perl, python) could be used for this purpose, or C or anything else.

JSBangs