.tex file remains in use by process when batch file is triggered by .Rnw Sweave processing.
Posted
by
drknexus
on Super User
See other posts from Super User
or by drknexus
Published on 2011-01-14T16:35:47Z
Indexed on
2011/01/14
16:56 UTC
Read the original article
Hit count: 302
This is a pretty specialized question. I'm using the Eclipse IDE in a Windows XP environment with the StatET plug-in so I can write R code as an R/Sweave document. This produces a .tex file that is then post processed by pdflatex.exe. When I create the file as normal everything works great (except maybe my file named russfnc2.Rnw seems to result in russfnc.pdf even though pdflatex.exe on the console window correctly says that the output is being writen to russfnc2.pdf). The big problem is when I trigger a batch file from within my Rnw code. My goal here is to spawn a side process that waits for the PDF to be made and uploads it to the server.
So the Rnw contains:
if(file.exists("rsp.finalize.bat")) {system("rsp.finalize.bat",wait=FALSE,invisible=FALSE)}
The batch file calls Rterm.exe to run a script:
setwd("C:/theprojectdirectory")
while(!file.exists("russfnc.pdf"))
{
Sys.sleep(1)
}
Sys.sleep(60)
At the end of that script, I use a shell call to launch psftp.exe and upload the files.
All of this works fine, when I use my Eclipse profile to trigger Sweave... that is unless I have that batch file at the end of the .Rnw. When it is located there, I get the error message pdflatex.exe: Permission denied: c:\thepath\thetexfile.tex
. After that, the .tex file (as far as XP is concerned) is in use by another process and I have to reboot in order to delete it (and, of course, the pdf is not made). If I manually trigger the batch file after pdflatex.exe has done its things, everything works fine.
How can I make this work correctly using the tools I'm familiar with vis., R and Dos-style batch files?
I'm not sure if this is a SuperUser question or a StackOverflow question, so I'm starting here.
© Super User or respective owner