Can't get wxExecute wxEXEC_SYNC to work. Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Can't get wxExecute wxEXEC_SYNC to work.

Post by kea_ » Wed Dec 10, 2008 8:23 am

Hello together,

I'm working on a program to start executables.
In my example 3 VBScripts. The scripts just count to 20.
If I call the scripts like this:
int code1 = wxExecute("CScript.exe D:/my_projects/cpp/Exec/App1.vbs", wxEXEC_SYNC);
int code2 = wxExecute("CScript.exe D:/my_projects/cpp/Exec/App2.vbs", wxEXEC_SYNC);
int code3 = wxExecute("CScript.exe D:/my_projects/cpp/Exec/App3.vbs", wxEXEC_SYNC);

The scripts are starting but they are passing each other.
Has anyone an idea?

Thank you very much.
kea_
Attachments
Output.jpg
Output.jpg (29.87 KiB) Viewed 1158 times

framepointer
Super wx Problem Solver
Super wx Problem Solver
Posts: 264
Joined: Mon Aug 07, 2006 3:25 pm
Location: Baia Mare, Romania
Contact:

Post by framepointer » Wed Dec 10, 2008 11:10 am

Hi.

Did you check if CScript.exe waits until the VBS is executed before returning or it returns immediately, before the VBS completes. Or do the VBS "load into the background" and keep running.
If any of the above is true, the output you have is quite normal since wxWidgets will wait only CScript.exe to return.

Regards
Software is like sex,
It's better when it's free.
~Linus Torvalds

kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Post by kea_ » Thu Dec 11, 2008 11:11 am

Hello framepointer,
for me it looks like a b... or it does not work.
See the screenshot.
I have the scripts in this way started an checked it width the procexp:
int code1 = wxExecute("CScript.exe D:/my_projects/cpp/Exec/App1.vbs", wxEXEC_SYNC);
int code2 = wxExecute("CScript.exe D:/my_projects/cpp/Exec/App2.vbs", wxEXEC_SYNC);
int code3 = wxExecute("CScript.exe D:/my_projects/cpp/Exec/App3.vbs", wxEXEC_SYNC);

Do you have an idea?

Thank you for your answer.
kea_
Attachments
script.jpg
script.jpg (36.45 KiB) Viewed 1139 times

kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Post by kea_ » Thu Dec 11, 2008 11:16 am

Hello framepointer,
for me it looks like a b... or it does not work.
See the screenshot.
I have the scripts in this way started an checked it width the procexp:
int code1 = wxExecute("CScript.exe D:/my_projects/cpp/Exec/App1.vbs", wxEXEC_SYNC);
int code2 = wxExecute("CScript.exe D:/my_projects/cpp/Exec/App2.vbs", wxEXEC_SYNC);
int code3 = wxExecute("CScript.exe D:/my_projects/cpp/Exec/App3.vbs", wxEXEC_SYNC);

Do you have an idea?

Thank you for your answer.
kea_
Attachments
script.jpg
script.jpg (36.45 KiB) Viewed 1138 times

framepointer
Super wx Problem Solver
Super wx Problem Solver
Posts: 264
Joined: Mon Aug 07, 2006 3:25 pm
Location: Baia Mare, Romania
Contact:

Post by framepointer » Thu Dec 11, 2008 1:56 pm

Hi.

Try to start a simple console application using wxExecute.
For example write a simple console app, that will print out it's first argument to stdout and exit wight after. Use that exe as a control.
Run your sample and see the output. This way you can test if there is anything wrong with the wxExecute().

But as said, I suspect that cscript.exe loads into the memory and returns control to your application before the vbs scripts are finished running. This way the 3 scripts run at the same time, hence the messed up output.

Regards
Software is like sex,
It's better when it's free.
~Linus Torvalds

kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Post by kea_ » Thu Dec 11, 2008 9:15 pm

Hello framepointer,
I've got my solution.
See the code below it does exactly what I like:

Code: Select all

void csExec::DoExecute(Execute exec){
    if(exec.bSync){
        wxProcess *process = new wxProcess(wxPROCESS_REDIRECT);
        long pid = wxExecute(exec.sExecute, wxEXEC_ASYNC, process);
        process->Redirect();

        if(process){
            wxInputStream *is = process->GetInputStream();
            wxTextInputStream tStream(*is);
            while(!is->Eof()){
                cout << tStream.ReadLine() << endl;
            }
        }
    }else{
        wxExecute(exec.sExecute, wxEXEC_ASYNC);
        cout << "ASync" << endl;
    }
}
I think it was not a problem of vbs because I coded a script width "WSHShell.Run "App1.vbs", 3, true" and width this it worked perfect.

Thank you for your help and
greetings from the snowing Liechtenstein
kea_

Post Reply