Re: Problem with Import[] and math.exe
- To: mathgroup at smc.vnet.net
- Subject: [mg98286] Re: Problem with Import[] and math.exe
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Sun, 5 Apr 2009 06:35:27 -0400 (EDT)
- References: <gr4jf8$a5a$1@smc.vnet.net>
andreas.kohlmajer at gmx.de wrote:
> Hi all!
>
> I spend several hours with a simple issue I don't understand. I would
> like to create a daily task on WinXP; I have already shortened my
> complex package to a very simple one, but it still doesn't work:
>
> This code works fine in the regular front end:
>
> In[1]:=
> ps=$PathnameSeparator;
> data=Import[FileNameJoin[{"C:",ps,"Temp",ps,"data.TSV"}]];
> Length[data]
> Export[FileNameJoin[{"C:",ps,"Temp",ps,"output.txt"}],data]
> Pause[2];
> Quit[];
>
> Out[3]= 1996
> Out[4]= "C:\\Temp\\output.txt"
>
> It also works fine using math.exe or mathkernel.exe by typing in
> everything manually. I have created a package c:\temp\test.m
> containing the code above.
>
> I can start math.exe and load the package and output.txt is created.
> The same happens with mathkernel.exe:
>
> Mathematica 7.0 for Microsoft Windows (32-bit)
> Copyright 1988-2009 Wolfram Research, Inc.
>
> In[1]:= Get["c:\\temp\\test.m"]
>
>
> However, if I try
>
> "C:\Program Files\Wolfram Research\Mathematica\7.0\math.exe" -initfile
> c:\temp\test.m
> or
> "C:\Program Files\Wolfram Research\Mathematica\7.0\mathkernel.exe" -
> initfile c:\temp\test.m
>
> (which are my batch commands for the daily task) , I get an error
> message:
>
> Mathematica 7.0 for Microsoft Windows (32-bit)
> Copyright 1988-2009 Wolfram Research, Inc.
>
> Import::infer: Cannot infer format of file data.TSV.
>
> Output.txt now contains Null. I also tried to give explicit importing
> information ("Table", "TSV", "FieldSeparator", encoding information
> etc.), but it doesn't work.
>
> I don't understand this. Do I need to load other .m-files (e.g. some
> init.m) too?
> The rest of my complex package (including SQL communication,
> statistical calculations, graphics generation) works fine, but I
> cannot load a simple tsv-file.
>
> My system:
> $Version = "7.0 for Microsoft Windows (32-bit) (February 18, 2009)"
> $OperatingSystem = "Windows"
>
> Are there any good references for notebook automation and evaluation
> using scheduled tasks under Windows? Thanks for any help!
>
I encountered a bug with Import (confirmed by someone at WRI) under
these conditions using version 6.0. My current method of starting
MathKernel is to use a small C program (which has an icon that can sit
on the desktop) which starts the kernel via MathLink, and passes it a
Get command on a file of Mathematica commands.
There are several ways to start Math - such as piping the input, or
using one of the other command line options, and I don't remember
exactly what worked and what didn't (there seemed to be various
gotcha's), but I ended up with the above solution, which works well.
David Bailey
http://www.dbaileyconsultancy.co.uk