delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/07/18/19:19:51

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
From: "Vaughn Balchunas" <vbalchunas AT doradosoftware DOT com>
To: <cygwin AT cygwin DOT com>
Subject: 1.3.2-1: problem running Expect from JNI.
Date: Wed, 18 Jul 2001 16:23:04 -0700
Message-ID: <NEBBJEDCIMIBNMMOKCMKOEGCCEAA.vbalchunas@doradosoftware.com>
MIME-Version: 1.0
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
Importance: Normal

------=_NextPart_000_0002_01C10FA5.EC2913A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

I have modified Mumit Khan's simple JNI example from
http://www.xraylith.wisc.edu/~khan/software/gnu-win32/
to make a native Expect library call using JNI.
What I did was add a line to call the exp_popen() function from the Expect
library libexpect526.a. (installed with cygwin setup).
What is displayed on the console when running the java program is a java
usage message as if the command 'java' had been entered on the terminal. The
Expect library call exp_popen is a wrapper to Expect's spawn and I am asking
it to spawn an FTP session.

This is the output:

~/oware35/native/java-jni/c:java Main
Java JNI
HOME = /cygdrive/d/work
Usage: java [-options] class [args...]
           (to execute a class)
   or  java -jar [-options] jarfile [args...]
           (to execute a jar file)

where options include:
    -cp -classpath <directories and zip/jar files separated by ;>
                  set search path for application classes and resources
    -D<name>=<value>
                  set a system property
    -verbose[:class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -showversion  print product version and continue
    -? -help      print this help message
    -X            print help on non-standard options
      0 [main] java 200 sync_with_child: child 97(0x364) died before
initialization with status code 0x1
    298 [main] java 200 sync_with_child: *** child state waiting for longjmp
After native call

This is the JNI source:

#include <stdio.h>
#include <stdlib.h>
#include <jni.h>
#include "HelloWorld.h"

#include "/usr/include/expect.h"

JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld (JNIEnv *env, jobject obj)
{
  char *home;
  printf("Java JNI\n");
  home = getenv ("HOME");
  printf("HOME = %s\n", (home) ? home : "(NULL)");

//      exp_popen("ls");
        exp_popen("ftp");

  return;
}

Attached is the makefile.


Finding a reliable NT port of Expect that I can call from java has been
difficult. If anyone has done this before or knows someone who can help me I
would appreciate it.


Vaughn Balchunas
Sr. Software Engineer
Dorado Software
www.doradosoftware.com
916-673-1104
vbalchunas AT doradosoftware DOT com

------=_NextPart_000_0002_01C10FA5.EC2913A0
Content-Type: application/octet-stream;
	name="Makefile.new"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="Makefile.new"

#
# Sample makefile to create Java JNI with Cygwin b20.1 tools. This *will =
not*
# work with Cygwin versions earlier than b20.1.
#=20
# The only difference from creating a regular DLL is to supply a =
different
# entry point, __cygwin_noncygwin_dll_entry AT 12, since Java is an MSVC =
app.
#
# See Makefile.nocyg if you want to use -mno-cygwin and build a Mingw =
JNI.
#

CC =3D gcc=20
CXX =3D c++

DEBUG =3D -g -Wall -O2
CXXFLAGS =3D $(DEBUG)=20
CFLAGS =3D $(DEBUG)=20
CPPFLAGS =3D -I /usr/include -I. -I$(JDK_ROOT)/include =
-I$(JDK_ROOT)/include/win32

#JDK_ROOT =3D c:/jdk1.1.7A

JDK_ROOT =3D d:/work/oware3rd/native/jdk1.2

AS =3D as
DLLTOOL =3D dlltool
DLLWRAP =3D dllwrap

#
# Various targets to build.
#
DLL_NAME =3D hello.dll
DLL_EXP_DEF =3D hello.def

all: $(DLL_NAME)

#
# DLL related variables. These are used when building the DLL. See =
later.
#

# Some tools require special CPP macros when building a DLL (eg., _DLL =
etc).
# Here we don't need anything.

DLL_CFLAGS =3D -DBUILDING_DLL=3D1 -D_DLL=3D1=20

# The default entry point defined by dllwrap is __cygwin_dll_entry AT 12=20
# defined in libcygwin.a, but that's only appropriate for Cygwin apps,
# but since Java is a MSVC app, we need to provide a different entry
# point. Note the leading underscore and the trailing @12.
# The -s flag strips the DLL to shrink the size.

#DLL_LDFLAGS =3D -Wl,-e,__cygwin_noncygwin_dll_entry AT 12 -s
DLL_LDFLAGS =3D -Wl

# any extra libraries that your DLL may depend on.
DLL_LDLIBS =3D /usr/lib/libexpect526.a /usr/lib/libtcl80.a

DLL_SRCS  =3D HelloWorldImp.cc
DLL_OBJS  =3D $(DLL_SRCS:.cc=3D.o)
DLL_OBJS :=3D $(DLL_OBJS:.c=3D.o)

###
#
# Making DLL
#
###

DLLWRAP_FLAGS =3D --output-def $(DLL_EXP_DEF) \
	--add-stdcall-alias \
	--driver-name $(CC) \
	$(IMAGE_BASE)

$(DLL_NAME): $(DLL_OBJS)
	$(DLLWRAP) $(DLLWRAP_FLAGS) -shared -o $(DLL_NAME) \
	    $(DLL_OBJS) $(DLL_LDFLAGS) $(DLL_LDLIBS)

#
# dependencies.
#

#
# default rules for building DLL objects. Note that client programs =
(ie.,
# the ones that *use* the DLL) have to be compiled without the =
DLL_CFLAGS
# flags.
#
.cc.o:
	$(CXX) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
.c.o:
	$(CC) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ $<

# Note that we omit the $(DLL_CFLAGS) for client programs.
usedll.o: %o: %c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<

clean:
	-rm -f $(OBJS) $(DLL_OBJS) $(DLL_NAME) $(DLL_EXP_LIB) $(DLL_EXP_DEF) =
$(TESTPROGS)



------=_NextPart_000_0002_01C10FA5.EC2913A0
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
------=_NextPart_000_0002_01C10FA5.EC2913A0--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019