MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

unable to run factor.exe

  • To: mathgroup at
  • Subject: [mg119698] unable to run factor.exe
  • From: Amandeep.Rekhi at
  • Date: Fri, 17 Jun 2011 05:52:36 -0400 (EDT)


Below I have explained the two scenario for which I tried to run the
code provided by the Mathematica:

Scenario     I:

Unable to run the exe provided factor.exe

When I tried to run the exe provided by Mathematica ( Location :
C:\Program Files\Wolfram
\PrebuiltExamples )

Below error is coming.  :           "Error detected by MathLink:
MathLink connection was lost.."

I have done all the required changes according to the link:

Please let me know if there are any other changes that need to be done
before running the program.

Scenario     II:

When tried to run the below program provided by Mathematica after
compiling in VS2005 then below error is coming.

"Error detected by MathLink: Connected MathLink program has closed the
link, but there might still be data underway.."

Process got hanged at the line marked RED in the below program:

If anybody have any idea on how to solve the issue then please let me

Thanks is advance.


#include <stdio.h>

#include <stdlib.h>

#include "mathlink.h"

static void init_and_openlink( int argc, char* argv[]);

static void error( MLINK lp);

MLENV ep = (MLENV)0;

MLINK lp = (MLINK)0;

int main(int argc, char* argv[])


      int pkt, n, prime, expt;

      long len, lenp, k;

      init_and_openlink( argc, argv);

      printf( "Integer to factor: ");

#if defined(_MSC_VER) && (_MSC_VER >= 1400)

      scanf_s( "%d", &n);


      scanf( "%d", &n);


      printf("vlue of n :%d\n",n);


      MLPutFunction( lp, "EvaluatePacket", 1L);


            MLPutFunction( lp, "FactorInteger", 1L);


                  MLPutInteger( lp, n);


      MLEndPacket( lp);



      while( (pkt = MLNextPacket( lp), pkt) && pkt != RETURNPKT) {

            MLNewPacket( lp);

            if (MLError( lp)) error( lp);



      if ( ! MLCheckFunction( lp, "List", &len)) error(lp);

//Error Message :Error detected by MathLink: Connected MathLink program
has closed the link, but there might still

be data underway..


      for (k = 1; k <= len; k++) {

            if (MLCheckFunction( lp, "List", &lenp)

            &&  lenp == 2

            &&  MLGetInteger( lp, &prime)

            &&  MLGetInteger( lp, &expt)


                  printf( "%d ^ %d\n", prime, expt);


                  error( lp);



      MLPutFunction( lp, "Exit", 0);

      return 0;


static void error( MLINK lp)


      if( MLError( lp)){

            fprintf( stderr, "Error detected by MathLink: %s.\n",



            fprintf( stderr, "Error detected by this program.\n");




static void deinit( void)


      if( ep) MLDeinitialize( ep);


static void closelink( void)


      if( lp) MLClose( lp);


static void init_and_openlink( int argc, char* argv[])



      int err;


      long err;

#endif /* MLINTERFACE >= 3 */

      ep =  MLInitialize( (MLParametersPointer)0);

      if( ep == (MLENV)0) exit(1);

      atexit( deinit);


      lp = MLOpenArgv( ep, argv, argv + argc, &err);


      lp = MLOpenArgcArgv( ep, argc, argv, &err);


      if(lp == (MLINK)0) exit(2);

      atexit( closelink);    


Thanks & Regards

Amandeep Singh

Email Disclaimer:

Information contained and transmitted by this e-mail (including any attachm=
ents) is confidential, proprietary and legally privileged data of Tata Tech=
nologies that is intended for use only by the addressee. If you are not the=
 intended recipient, you are notified that any review, use, dissemination, =
distribution, copying or printing of this e-mail is strictly prohibited. Yo=
u are requested to delete this e-mail or any copies immediately and notify =
the sender by reply email. Internet communications cannot be guaranteed to =
be timely, secure, error or virus-free.  Tata Technologies does not accept =
any liability for virus infected email or errors or omissions or consequenc=
es which may arise as a result of this e-mail transmission. To know more ab=
out Tata Technologies please visit

  • Prev by Date: Re: How to Do a Replacement with Two Conditions
  • Next by Date: Re: Filtering of the higher frequency terms.
  • Previous by thread: webMathematica Export
  • Next by thread: Re: Filtering of the higher frequency terms.