Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to start one program from another
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
chrisbrown




PostPosted: Thu Jul 08, 2010 2:19 pm   Post subject: RE:How to start one program from another

ps is a command-line program, not a Turing keyword; it won't help you here.

While your launcher can't talk directly to a process that it spawns, you could modify those programs to be launched to write a new file on startup and delete on completion.

Then have your launcher continuously check for the existence of that file. If it exists, another program is running, so the launcher should become/stay hidden. Otherwise, a program has either finished or nothing has been launched, so the launcher should be visible.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Jul 08, 2010 2:21 pm   Post subject: RE:How to start one program from another

Of course, should the program end unexpectedly via exceptions, it might not have a chance to write about its exit status. The only system that knows about the status of a process for a fact is the kernel.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
chrisbrown




PostPosted: Thu Jul 08, 2010 3:26 pm   Post subject: RE:How to start one program from another

True. Windows' 'tasklist' program will display running processes, but even with a batch file and output redirection, I can't figure out a way to stop the command prompt from opening momentarily while it executes, so I don't think that's going to work for OP.

Without decent CLI integration, the heartbeat method is probably the best way to go. I think it was discussed somewhere recently.
mirhagk




PostPosted: Fri Jul 09, 2010 9:25 am   Post subject: RE:How to start one program from another

How about have both programs connect to each other on the loop back address, I forget the syntax to write this exactly (almost 2 years since I really worked with Turing other than simple operations).

If the host program calls the new program, and the new program connects to the host program on the loopback address, then you can have both programs communicate to each other, being able to not only tell about whether the file is open or not, but also be able to send commands back and forth, for instance closing the child program from within the main program.

I am going to fool around a bit with the network part of turing, I'll be back in 5-10 minutes with some code that should work.
mirhagk




PostPosted: Fri Jul 09, 2010 10:00 am   Post subject: Re: How to start one program from another

So I believe this code should work (my turing doesn't compile programs right, stupid 4.1.1)

Here's the main program
Turing:

put "starting program.exe" %obviosuly your code would go before here
var address : string %used to store the address of the connecting computer
if (Sys.Exec ("program.exe") = false) then %start the file
    put "program could not be found" %if it doesnt start tell the user
else
    put "waiting for program to connect to main"
    var client := Net.WaitForConnection (9000, address) %wait for a connection
    put "connected, checking to make sure that the program is connected still" %now the program is connected
    var timeSinceLast := 0 %the amount of time that's passed since last msg was recieved
    var msg : char %to store the recieved message
    loop
        if (Net.CharAvailable (client)) then %if there is anything to read
            get : client, msg %get it from the client
            timeSinceLast := 0 %reset timer
            put msg .. %display the one character
        else
            timeSinceLast += 1 %if nothing to read add to the timer
        end if
        exit when timeSinceLast > 1000 %if the timer is above 1000 (1 second)
        %the program has "timed out" so we know it has ended
        delay(1) %delay by a millesecond
    end loop
end if


and the program (you need to compile it first)
Turing:

put "started, connecting to host"
var host := Net.OpenConnection ("127.0.0.0", 9000) %connect to host and store the connection in an int
put "connected, transmitting welcome message" %now it's connected
loop
    put : host, "hi" %write to the host that it's still connected
    exit when hasch () %exit when you press any key
    delay (5) %delay by 5 milliseconds (just so the byte stream doesn't get to full
end loop

Cezna




PostPosted: Fri Jul 09, 2010 10:28 am   Post subject: RE:How to start one program from another

@ mirhagk
I'm not sure exactly what that will do, but it looks to me like you are just writing the client program into the launcher's run window.
mirhagk




PostPosted: Fri Jul 09, 2010 11:32 am   Post subject: RE:How to start one program from another

No it runs the client, and the client just says hi until it ends, then it times out on the hosts side, letting you know when it's done
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 22 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: