Alaska Software Inc. - Runshell() Crash in Win7-64bit
Username: Password:
AuthorTopic: Runshell() Crash in Win7-64bit
Clayton Jones Runshell() Crash in Win7-64bit
on Mon, 17 Sep 2012 22:45:04 -0400
Hello All,

I recently got a new laptop and it runs Win7-64bit.  In my IDE app
there are many calls to Runshell() for various things and they all
work ok in Win7-32bit on my desktop machine, but some of them (not
all) crash in 64bit.

I have a wrapper function to ShellExecuteA() and I have been able to
substitute it for Runshell() in all but one instance, and that is
calling Pbuild.exe to compile an app.  Here is the code that works ok
in Win7-32bit

    RunShell("/C Pbuild PROJECT > xxx.log")

This opens a command window in which the stream of file names appear
as they are compiled, and then it closes.  The output of Pbuild is
written to the text file xxx.log which I then display in a text file
viewer window.  This has worked fine for years in XP, Vista and now
Win7, but all 32bit versions.  In Win7-64 bit this generates a runtime
error.

I have spent several hours trying every permutation of Runshell() and
ShellExecuteA I can think of, with no luck.  It doesn't crash, it just
doesn't do anything (no compiling, no writing to xxx.log).  It always
returns the numeric value 42.  All the error codes for this function
range between 0 and 31.  I can't find any reference to 42 on-line.

Does anyone have any experience with this?

I have seen the thread "Runshell in win7" in the "Generic" section,
but all the solutions offered there refer to ShellExecuteA which I
have already tried.  I'm stuck on this one.  Any help or clues will be
very much appreciated.


Regards,
Clayton

Clayton Jones   www.cjcom.net 
 Top-Down Library for Xbase++
 X-DBU Database Utility   
 X-MEMO Memo Field Replacement
 Spell-X  Spell Checking for Xbase++
Pablo Botella NavarroRe: Runshell() Crash in Win7-64bit
on Tue, 18 Sep 2012 16:50:06 +0200
Hi,

>    RunShell("/C Pbuild PROJECT > xxx.log")
It must work whithout any trouble. I'm 99% sure in your case will be just a path issue so double check that the pbuild.exe and all the dependent dlls are pointed by the path environment variable for the user executing the program.

I'm usually using CreateProcess() ( search for the TRunProcess.prg inside http://www.xbwin.com/devcon2012/WinAPIWorkshop.zip ) in combination with the corresponding STARTUPINFO
so I able to change or replace the environment and redirect the output to a pipe or a file handle ,  check for termination , retrieve the resul or even kill the process if suspect is hanged.

As TRunProcess need the full path to executable, you can use 
buffer := ChrR(0,512)
@shell32:FindExecutableA("pbuild.exe",cAppDir(),@buffer)
 TrimZ(buffer)
to search the location using the path environment var

Regards,
Pablo
Pablo Botella NavarroRe: Runshell() Crash in Win7-64bit
on Tue, 18 Sep 2012 16:52:28 +0200
>( search for the TRunProcess.prg inside http://www.xbwin.com/devcon2012/WinAPIWorkshop.zip ) 
Sorry,wrong link ( the server is case sensitive)
This is the correct:
http://www.xbwin.com/devcon2012/WinAPIWorkShop.zip
Clayton Jones Re: Runshell() Crash in Win7-64bit
on Tue, 18 Sep 2012 12:52:17 -0400
Hello Pablo,

>>    RunShell("/C Pbuild PROJECT > xxx.log")
>It must work without any trouble. I'm 99% sure in your case will be just a path issue 
>so double check that the pbuild.exe and all the dependent dlls are pointed by the path 
>environment variable for the user executing the program.

I wish it was that simple, but I think there's more going on here.
(BTW, this code is in my IDE app which is bundled with TD Library.
It's used by TD developers, but the code is in my app, not in the
developers' apps.)

In one place Runshell works ok and in 4 other places it fails, even
with fully qualified paths.  Here's the code

1* this fails, even though cDbu contains a full path string to the DBU
app and cPathname contains the full path to the DBF to be opened

   IF fExists(cDbu)   open DBU app
      RunShell("/C START " + cDbu + " " + cPathname)

2* this works fine (opens a prg in the editor app). Both vars contain
full path strings with filenames

   RunShell(cPathname,cEditor,.T.) 

3* this fails, even though Pbuild is in the Alaska folders specified
in PATH (set by the Alaska installation).  Curdir() ensures that
project.xpj and xxx.log are found within the project folder

   curdir(cProjpath)   project path
   RunShell("/C Pbuild PROJECT > xxx.log")
   curdir(cProgpath)   IDE app path

4* this fails (running project app with debugger, even though xppdbg
is in the Alaska folders specified in PATH).  cPathApp contains a
complete path string and exe file name)

   RunShell("/C START XPPDBG " + cPathApp)

5* this fails (running project app without debugger).

   RunShell("/C START " + cPathApp)

--------------------

All of the above code works fine in Win7-32 bit (and XP-32 and
Vista-32).  If the code has flaws shouldn't it fail there as well?  It
has been in use for over 10 years.

I have fixed all the failures exept #3 using my ShellExecuteA()
function.  #3, the compiler, has me stumped. 


Regards,
Clayton

Clayton Jones   www.cjcom.net 
 Top-Down Library for Xbase++
 X-DBU Database Utility   
 X-MEMO Memo Field Replacement
 Spell-X  Spell Checking for Xbase++