0

我想使用批处理文件移动文件,因为我确实使用下面的代码,该过程似乎成功执行,但文件没有被传输。这段代码有什么问题吗?

    STARTUPINFO osi;
    PROCESS_INFORMATION pi;
    ZeroMemory( &osi, sizeof(osi) );
    osi.cb = sizeof(capinfo);
    ZeroMemory( &pi, sizeof(pi) );

    wchar_t cmd[8192];
    wchar_t ocmd[8192];
    char ocmd1[8192];
    swprintf_s(ocmd,sizeof(ocmd),L"%s\\%s.bat",capodd->templocation,capodd->wcurrentoutput);
    sprintf_s(ocmd1,sizeof(ocmd1),"%ls\\%s.bat",capodd->templocation,capodd->currentoutput);
    FILE * tempbat = fopen(ocmd1,"w");

    swprintf_s(cmd,8192,L"move %s\\%s.mp4 %s\\%s.mp4",capodd->templocation,capodd->wcurrentoutput,capodd->destination,capodd->wcurrentoutput);
    fprintf(tempbat,"%ls\n",cmd);
    //swprintf_s(cmd,8192,L"move %s\\%s.txt %s\\%s.txt",capodd->templocation,capodd->currentoutput,capodd->destination,capodd->currentoutput);
    //fprintf(tempbat,"%ls\n",cmd);
    //fprintf(tempbat,"del %ls\n",ocmd);
    fclose(tempbat);
    swprintf_s(cmd,sizeof(cmd),L"cmd /c %s",ocmd);
    // just for fun, sleep for twice my latency to make sure the other half of the graph has started
    Sleep(1000 *2); // of course, this means our overlap better be within 2x of the periodicity

    if (!CreateProcess(NULL,cmd,NULL,NULL,FALSE,0,NULL,NULL,&osi,&pi)) {
        fprintf(capodd->c_pF,"couldn't execute copy %d\n",GetLastError());
    }
4

1 回答 1

1

您的代码中有 2 个问题:
1-osi.cb = sizeof(capinfo);应更改为osi.cb = sizeof(osi);
2- 使用sizeof()inswprintf_s不正确。您应该使用_countof()它来代替它,或者sizeof()在使用静态数组时可以省略。
我测试了这段代码,没有其他问题。

于 2012-06-18T18:36:54.067 回答