Jump to content

ProcessWaitClose


Recommended Posts

I'm attempting to use ProcessWaitClose() to pause script while an external command is being executed. Not only does the script seem to ignore ProcessWaitClose(), but the command itself seems to terminate prematurely. code is pasted below, any help resolving this would be greatly appreciated.

$PID=Run(@ComSpec & " /c" & 'dir /s '& $dirThis & " >> null", "", @SW_HIDE);
  ProcessWaitClose($PID);
  $filePath=@WorkingDir & "\null";
  $saveFile = FileSaveDialog( "Choose a name.", "", "Evo Data Catalog (*.edc;)", 18,"");
  $mov=FileCopy($filePath,$saveFile & ".edc");
Edited by dragonkeeper
Link to comment
Share on other sites

A space is missing between c and dir...

Thanks wakillion, but even with the addition of a space between c and dir, the command fails to execute. If i remove ProcessWaitClose line, the command executes as intended. If I switch the /c for the /k parameter and maximize the window instead of hiding it. I get the following error in the cmd window "The process cannot access the file because it is being used by another process."

Link to comment
Share on other sites

  • Developers

2 remarks:

- Shouldn't null be nul?

- Why not use RunWait in stead of Run() and adding ProcessWaitClose()?

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks for your response Jos.

- Shouldn't null be nul?

Null is the name of a file where the results of the dir command are appended.

- Why not use RunWait in stead of Run() and adding ProcessWaitClose()?

I get the same result when using RunWait(), which led me to try ProcessWaitClose() instead.

I feel like I'm missing something really simple, but kinda lost as to what.Thanks for the fast responses to my post.

Link to comment
Share on other sites

  • Developers

There enough references to your posted error on the internet so that should be a good place to start.

The ProcessClose() / runwait(0 has nothing to do with it and try to just simply run it from the CMD prompt to see what happens.

Post some script that we can run showing your problem when you want us to do some testing..

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

There enough references to your posted error on the internet so that should be a good place to start.

The ProcessClose() / runwait(0 has nothing to do with it and try to just simply run it from the CMD prompt to see what happens.

Post some script that we can run showing your problem when you want us to do some testing..

Jos

Thanks Jos. I did indeed google the error message before posting in the forum. And found nothing the pertains to this specific problem. The error only occurs when attempting to use either the RunWait() or ProcessWaitClose() commands. I'm able to run the dir command and pipe it's output to a text file using a command prompt with out issue. The script runs as well if i leave out the RunWait()/ProcessWaitClose() and FileSaveDialog() commands. Introducing the FileSaveDialog() caused me to find a way to pause the script as FileSaveDialog() was executing before the dir command appended the text file.

Here is the complete code.

"I've stripped out the majority of error handling logic in an attempt to get the basic code functioning".

$dirThis=FileSelectFolder("Select Drive or Folder to Catalog.", "" );

if DriveStatus($dirThis) == "READY" Then
  ;if FileExists("null") Then
    ; FileDelete("null")
 ;EndIf
 FileOpen(@ScriptDir & "\null", 2);
    fileWriteLine("null", "[INFO]");
    fileWriteLine("null", "DriveType=" & DriveGetType($dirThis));
    fileWriteLine("null", "Path=" & $dirThis);
    fileWriteLine("null", "Label=" & DriveGetLabel(StringLeft($dirThis,3)));
    fileWriteLine("null", "Serial=" & DriveGetSerial(StringLeft($dirThis,3)));
    fileWriteLine("null", "FileSystem=" & DriveGetFileSystem(StringLeft($dirThis,3)));
    fileWriteLine("null", "DiskSpace=" & Round(DriveSpaceTotal(StringLeft($dirThis,3))/1024,2) & "GB") ;
    fileWriteLine("null", "FreeSpace=" & Round(DriveSpaceFree(StringLeft($dirThis,3))/1024,2) & "GB") ;
    $D=FileGetTime("null",1);
    fileWriteLine("null", "CreateTime=" & $D[3] & ":" & $d[4] & ":" & $d[5]);
    fileWriteLine("null", "CreateDate=" & $D[1] & "/" & $d[2] & "/" & $d[0]);
    fileWriteLine("null", "");
    fileWriteLine("null", "[Comments]");
    fileWriteLine("null", "");
    fileWriteLine("null", "");      
  FileClose( "\null");
  ;$PID=Run(@ComSpec & " /c dir /s "& $dirThis,@SW_HIDE &" >> null");
  $PID=Run(@ComSpec & " /k " & 'dir /s '& $dirThis & " >> null", "", @SW_MAXIMIZE);
  RunWait(@ComSpec & " /k " & 'dir /s '& $dirThis & " >> null", "", @SW_MAXIMIZE);
  $filePath=@WorkingDir & "\null";
  ;ProcessWaitClose($PID);
  ;ProcessWaitClose($PID);
  ;$saveFile = FileSaveDialog( "Choose a name.", "", "Evo Data Catalog (*.edc;)", 18,"");
    ;$mov=FileCopy($filePath,$saveFile & ".edc");
    
else
    if DriveGetType($dirThis)=="CDROM" Then
        MsgBox(16,"Drive Status","Drive not ready. Please Insert Disk")
    ELSE 
        MsgBox(16,"Drive Status","Drive Not Ready") 
    EndIf       
EndIf

I appreciate all the help I really need to get this to work. I'm upgrading my media PC to Windows 7, but have on hurdle to over come. MS in their infinite wisdom decided to remove the "SAFRCFileDlg.FileSave" from Windows 7, forcing me to update my homegrown media center application.

Edited by dragonkeeper
Link to comment
Share on other sites

  • Developers

This is wrong:

FileOpen(@ScriptDir & "\null", 2);
    fileWriteLine("null", "[INFO]");
    ; -- snip --
    fileWriteLine("null", "");      
    FileClose( "\null");

Should be:

$fh = FileOpen(@ScriptDir & "\null", 2);
    fileWriteLine($fh, "[INFO]");
    ; -- snip --
    fileWriteLine($fh, "");      
    FileClose( $fh);
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...