[Scilab-users] running Windows (win32 terminal) program in scilab

Stéphane Mottelet stephane.mottelet at utc.fr
Wed Oct 5 16:03:44 CEST 2022


Hello,

I think that the following attempt could be a quick and dirty solution. 
The trick is to launch the command in the background and to redirect the 
output in a text file, whose length is checked every dt seconds, which 
allows to print the new content during the command execution. The 
command stops when there is no change after 2 seconds (can be ajusted 
below):

function cmd(cmdstr)
     tmpfile=fullfile(TMPDIR,"out.txt");
     host("start /B "+cmdstr +" > "+tmpfile)
     s=0;
     ns=0;
     dt=1;
     fd=mopen(tmpfile,"rb");
     while %t
         info=fileinfo(tmpfile)
         if info(1) > s
             ns = 0;
             str = mgetstr(info(1)-s,fd)
             mprintf("%s",str);
             s=info(1)
         elseif ns < 2
             sleep(dt,"s")
             ns = ns+1;
         else
             break
         end
     end
     mclose(fd);
     mdelete(tmpfile);
endfunction

--> cmd("ping www.google.fr")

Pinging www.google.fr [216.58.206.227] with 32 bytes of data:
Reply from 216.58.206.227: bytes=32 time=2ms TTL=118
Reply from 216.58.206.227: bytes=32 time=2ms TTL=118
Reply from 216.58.206.227: bytes=32 time=2ms TTL=118
Reply from 216.58.206.227: bytes=32 time=2ms TTL=118

Ping statistics for 216.58.206.227:
     Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
     Minimum = 2ms, Maximum = 2ms, Average = 2ms

-->

Le 05/10/2022 à 11:11, jp.konta at cyberia.pl a écrit :
> Hi,
> I need to run external (win32) terminal program inside scilab. I've tried scilab functions like: host(), dos(), unix in different variants (unix_w, etc).
> The problem is that all of them are not showing output of the program during execution. Unfortunatelly I need to show info from win32 terminal program during execution (showing it after execution is too late).
>
> In Octave there is function system(), which shows outputs during program is run. Both standard input and ouputs are passed to Octave Command Window, (i.e. program is really waiting for pressing a key)
>>> system("pause");
> Press any key to continue . . .
> Is there any possibility to achieve something similar in Scilab? At least if interaction not possible, is it possible to show standard output before called program is ended?
>
> Kind regards,
> Jan
> _______________________________________________
> users mailing list - users at lists.scilab.org
> Click here to unsubscribe: <mailto:users-unsubscribe at lists.scilab.org>
> https://antispam.utc.fr/proxy/v3?i=WjB4M1dJWGJJMnNGTHV5MuAPDwEdQko7KGyaWIIeme0&r=Skk2OVhvdXl2cm1uOWJtRLRPDrgr4YiCABksjbHu_Gv8eNkcUiMzd6MxV8KbAPI5&f=M2FwZHlGNnU1aUlkc09ZNN6FtQAZUfRagBYPQiUfaoT45ZkXHKKVm0cOGvv2yMCS&u=http%3A//lists.scilab.org/mailman/listinfo/users&k=CXOq

-- 
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
http://www.utc.fr/~mottelet




More information about the users mailing list