Menu

compress file with createprocess on windows with error code 1

guang
2016-12-08
2016-12-09
  • guang

    guang - 2016-12-08

    Question description

    Process flow such as follows
    int ZipPack(char* p_pcCmd)
    {
    _PROCESS_INFORMATION l_sProInfo={0};
    STARTUPINFO l_sStartupInfo={0};

    if (!CreateProcess(NULL, p_pcCmd, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &l_sStartupInfo, &l_sProInfo))   
    {
        return 1;
    }
    
    WaitForSingleObject(l_sProInfo.hProcess,INFINITE);
    
    DWORD dwErr = 0;
    GetExitCodeProcess(l_sProInfo.hProcess, &dwErr);
    
    CloseHandle(l_sProInfo.hProcess); 
    CloseHandle(l_sProInfo.hThread);
    
    return 0;
    

    }

    For example to use function ZipPack
    char l_acBuf[]={"D:\Test\7z a -t7z "D:\Test\log.7z" "D:\Test\log\log1.txt" "D:\Test\log\log2.txt" "D:\Test\log\log3.txt""}
    ZipPack(l_acBuf);

    After GetExitCodeProcess is executed, dwErr is equal 1.Manual says error code with 1 means warning.

    In fact file log.7z contains nothing. Also I find that these three files cannot open and information of pop message box is "The process cannot access the file because it is being used by another process".

    7z version used is 16.2 and 16.4

    Thanks in advance for any suggestion.

     
  • Igor Pavlov

    Igor Pavlov - 2016-12-08

    try -ssw : compress shared files.

    -ssw
    
     
  • guang

    guang - 2016-12-08

    Thanks for response.

    Something needs to clear that these three files to be compressed don't be used by other process. These files can't be open after 7z.exe is invoked by CreateProcess to compresses them.

    If input parameter p_pcCmd in CreateProcess is typed completed in console window, these files are compressed successfully.

    Where is the problem when compressed file with error code equal 1. In other words, what is the root for this situation.

     
  • guang

    guang - 2016-12-09

    Thanks for reply patiently.
    I found the reason is due to my foolish operation don't close file when open file.
    Very much thanks.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.