# Plink exe and dos

**URL:** <https://scilab.discourse.group/t/plink-exe-and-dos/88>\
**Category:** General usage\
**Created:** [April 28, 2023, 1:17pm UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88 "2023-04-28T13:17:23Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [April 28, 2023, 1:17pm UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/1 "2023-04-28T13:17:23Z")

</div>

Hi i want to read some datas over the serial port with plink.exe. in the dos shell it works

 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/7ed8d9a9d29635137bef7b8d12b99e4db133e86e.png)  
with scilab terminal i get  
 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/790941410881c806c96f0d3c41ada9a61a39adc3.png)  
and i tried several cmd commands and echo.

Any idea?

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [May 2, 2023, 7:17am UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/2 "2023-05-02T07:17:53Z")

</div>

Hello,

It really depends on your goal: do you just want to asynchronously display data coming from the serial port or read and process the data within Scilab ? In the first case (although the code can be adapted to the second) I posted some time ago on the ML the following function which displays the asynchronous output of a dos command (timeout of 2 seconds can be customized):

```auto
function cmd(cmdstr)
    tmpfile=fullfile(TMPDIR,"out.txt");
    host("start /B "+cmdstr +" > "+tmpfile)
    s=0;
    ns=0;
    dt=1;
    TIMEOUT=2;
    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 < TIMEOUT
            sleep(dt,"s")
            ns = ns+1;
        else
            break
        end
    end
    mclose(fd);
    mdelete(tmpfile);
endfunction 

```

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [May 2, 2023, 7:37am UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/3 "2023-05-02T07:37:22Z")

</div>

thanks, i will tested it and see if it works 🙂

M.f.G. Pascal

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [May 3, 2023, 11:41am UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/4 "2023-05-03T11:41:54Z")

</div>

I tested it with the command and still saw nothing.

Actually i wanna read and process the data within Scilab. But what is the difference if i do it in Windows shell or scilab terminal?

Is there maybe a way or should the datas piped to scilab terminal?

M.f.g. Pascal

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [May 3, 2023, 11:46am UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/5 "2023-05-03T11:46:31Z")

</div>

Can you check that you get some output with

```auto
cmd("ping www.google.com")

```

?

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [May 3, 2023, 12:45pm UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/6 "2023-05-03T12:45:21Z")

</div>

> [@mottelet](#):
>
> `cmd("ping www.google.com")`

Yes it works with ping

 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/7e988d322c3ca938c5550687310a9ded0f943879.png)

but i think with plink it exits serial before mqtt gives the publishing answer to serial

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [May 3, 2023, 1:25pm UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/7 "2023-05-03T13:25:16Z")

</div>

I think that the redirection of the standard output fails when using plink. Can you try the following on the DOS command line:

```auto
start /B cmd > out.txt

```

where `cmd` has to be replaced by the full plink command. BTW, can you include your outputs as text (instead of screenshots) ?

S.

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [May 3, 2023, 1:40pm UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/8 "2023-05-03T13:40:03Z")

</div>

ok, i can make it so, than read the txt into scilab, this should work.

But my goal its todo directly, having the strings as an array abd then make the evaluation with plotting all in scilab.

Tricky i know 🙂

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [May 3, 2023, 1:43pm UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/9 "2023-05-03T13:43:38Z")

</div>

if i do it with txt. i can use putty and read its logfile and that’s it. but with plink iwanted to avoid this part with txt. 🙂

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [May 3, 2023, 1:44pm UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/10 "2023-05-03T13:44:08Z")

</div>

No, I meant that you should try the above only to test if redirection of plink works or not. Maybe just adding quotes before and after the command would make it work from Scilab. Anyway, if the redirection works, then the file would be updated and read in Scilab by cmd().

S.

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [May 3, 2023, 1:54pm UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/11 "2023-05-03T13:54:56Z")

</div>

> [@mottelet](#):
>
> `start /B cmd > out.txt`

 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/e7bc72d970c7e7aa240e335dffba299277322b4b.png)  
i thin the redirection functions but afterwards nothing?  
 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/398df071b3409ed1035ea343266772d911a3c7b4.png)  
not event found the out.txt

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [May 3, 2023, 1:58pm UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/12 "2023-05-03T13:58:46Z")

</div>

Can you add `2>&1` at the end and try again (see [https://stackoverflow.com/questions/45414288/plink-command-results-not-being-saved-to-local-text-file](https://stackoverflow.com/questions/45414288/plink-command-results-not-being-saved-to-local-text-file)) ?

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [May 3, 2023, 2:13pm UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/13 "2023-05-03T14:13:48Z")

</div>

> [@mottelet](#):
>
> 2\>&1

 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/91f0152009ce7358a47d71fa9cb25540d640f29b.png)  
 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/3fa213cbed90a84eea6a335c816f276d02eb5b60.png)  
didn’t work. could we have this conversation tomorrow or next time? I need to go. it is a interresting subject but not soooo urgent. so maybe till next time 🙂 bye

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [May 3, 2023, 2:24pm UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/14 "2023-05-03T14:24:48Z")

</div>

Ok. Just make sure `out.txt` above is actually empty and that you updated the code of `cmd` like this (third line):

```auto
function cmd(cmdstr)
    tmpfile=fullfile(TMPDIR,"out.txt");
    host("start /B "+cmdstr +" > "+tmpfile+" 2>&1")
    s=0;
    ns=0;
    dt=1;
    TIMEOUT=2;
    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 < TIMEOUT
            sleep(dt,"s")
            ns = ns+1;
        else
            break
        end
    end
    mclose(fd);
    mdelete(tmpfile);
endfunction 

```

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [May 4, 2023, 6:38am UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/15 "2023-05-04T06:38:38Z")

</div>

Hi again, i made it like the you  
 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/6b9ae99ff11080e5da65665dcfba298d4fe47844.png)  
and run in terminal  
 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/65ec9dc331b7eef4a9aa6bc03ac5b85e37a24c6c.png)  
it almost worked lost one O like opening but the handle was not acceptet could it be the arrow at the dataline begining? Alt+27 : ← ?

---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [May 4, 2023, 7:00am UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/16 "2023-05-04T07:00:49Z")

</div>

> [@pascal](#):
>
> it almost worked lost one O like opening but the handle was not acceptet could it be the arrow at the dataline begining? Alt+27 : ← ?

No idea. Maybe try to open the file in text mode `'rt'` instead of `'rb'` ? Anyway, glad that it works !

---

<div class="post-metadata">

**Author:** ![pascal](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/pascal/32/40_2.png) [@pascal](https://scilab.discourse.group/u/pascal)\
**Post date:** [May 4, 2023, 7:13am UTC](https://scilab.discourse.group/t/plink-exe-and-dos/88/17 "2023-05-04T07:13:29Z")

</div>

‘rt’ the same like ‘rb’, but now with the O of Opening.  
So, lets leave it here, maybe next time with a more accurate string from serial.  
So, thanks for now and hope to see the next release 🙂

M.f.G. Pascal
