Discussion:
[Scilab-users] Running external program
Lester Anderson
2015-12-03 11:43:32 UTC
Permalink
Hello,

I have the windows version of Scilab (currently 5.4.1), but would like
to run an external program (e.g. gmt software) and return or use the
output in the Scilab code:

As a rough algorithm example (.sce):

//run the gmt program grdinfo.exe - extract data as single column z-matrix)

grd2xyz faa.grd -ZTLa > faa.txt

scilab: assign matrix output to variable for use in Scilab etc.

Any pointers would be helpful.

Lester
selieff
2015-12-03 14:10:40 UTC
Permalink
The command you want is 'dos':

dos('grd2xyz faa.grd -ZTLa > faa.txt')

If the command line is complex or needs to include names defined elsewhere,
it is sometimes helpful to use msprintf to create the string first

complex_command = msprintf(...)

and then issue it using the string variable

dos(complex_command,'-echo')

The '-echo' is optional but nice to see in the command window.

The resulting 'faa.txt' file from GMT can be read with whatever function
makes the most sense for the format (fscanfMat perhaps?).

Stefan
Post by Lester Anderson
Hello,
I have the windows version of Scilab (currently 5.4.1), but would like
to run an external program (e.g. gmt software) and return or use the
//run the gmt program grdinfo.exe - extract data as single column z-matrix)
grd2xyz faa.grd -ZTLa > faa.txt
scilab: assign matrix output to variable for use in Scilab etc.
Any pointers would be helpful.
Lester
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
--
View this message in context: http://mailinglists.scilab.org/Scilab-users-Running-external-program-tp4033159p4033160.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Stefan Elieff
2015-12-03 13:57:05 UTC
Permalink
The command you want is 'dos':

dos('grd2xyz faa.grd -ZTLa > faa.txt')

If the command line is complex or needs to include names defined
elsewhere, it is sometimes helpful to use msprintf to create the string
first

complex_command = msprintf(...)

and then issue it using the string variable

dos(complex_command,'-echo')

The '-echo' is optional but nice to see in the command window.

The resulting 'faa.txt' file from GMT can be read with whatever function
makes the most sense for the format (fscanfMat perhaps?).

Stefan
Post by Lester Anderson
Hello,
I have the windows version of Scilab (currently 5.4.1), but would like
to run an external program (e.g. gmt software) and return or use the
//run the gmt program grdinfo.exe - extract data as single column z-matrix)
grd2xyz faa.grd -ZTLa > faa.txt
scilab: assign matrix output to variable for use in Scilab etc.
Any pointers would be helpful.
Lester
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
Lester Anderson
2015-12-03 15:55:33 UTC
Permalink
Hello Stefan,

Thanks for the pointers. I have tried with a small section of scripting:

// Test script to launch and process GMT commands
dos('grd2xyz FAA.grd -ZTLa -V > faa.txt','-echo') // works fine
dos('grdinfo FAA.grd','-echo') // works fine
dos('grdinfo FAA.grd -C | gawk "{nx=$10; ny=$11}; {print nx, ny}" >
nxy.txt','-echo') // error

The third line fails with an error (gawk is in the PATH), perhas due
to the piping (|) or some other issue:

dos('grdinfo FAA.grd -C | gawk "{nx=$10; ny=$11}; {print nx, ny}" >
nxy.txt','-echo')
!--error 3
Waiting for right parenthesis.
at line 4 of exec file called by :
exec('C:\SS20-work\FAA_EAfrica\test_faa.sce', -1)

Are there limitations with this route?

Thanks
Lester
Post by selieff
dos('grd2xyz faa.grd -ZTLa > faa.txt')
If the command line is complex or needs to include names defined elsewhere,
it is sometimes helpful to use msprintf to create the string first
complex_command = msprintf(...)
and then issue it using the string variable
dos(complex_command,'-echo')
The '-echo' is optional but nice to see in the command window.
The resulting 'faa.txt' file from GMT can be read with whatever function
makes the most sense for the format (fscanfMat perhaps?).
Stefan
Post by Lester Anderson
Hello,
I have the windows version of Scilab (currently 5.4.1), but would like
to run an external program (e.g. gmt software) and return or use the
//run the gmt program grdinfo.exe - extract data as single column z-matrix)
grd2xyz faa.grd -ZTLa > faa.txt
scilab: assign matrix output to variable for use in Scilab etc.
Any pointers would be helpful.
Lester
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
Dang Ngoc Chan, Christophe
2015-12-03 16:47:34 UTC
Permalink
Hello,
De : Lester Anderson
Envoyé : jeudi 3 décembre 2015 16:56
dos('grdinfo FAA.grd -C | gawk "{nx=$10; ny=$11}; {print nx, ny}" >
nxy.txt','-echo')
!--error 3 Waiting for right parenthesis.
In some cases, you need to use two quotes to tell that you want the character quote and that it is not the end of the string.

Don't know if it applies here, but maybe you could try.

--
Christophe Dang Ngoc Chan
Mechanical calculation engineer
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
Samuel Gougeon
2015-12-03 18:14:02 UTC
Permalink
Post by Lester Anderson
Hello,
De : Lester Anderson
Envoyé : jeudi 3 décembre 2015 16:56
dos('grdinfo FAA.grd -C | gawk "{nx=$10; ny=$11}; {print nx, ny}" >
nxy.txt','-echo')
!--error 3 Waiting for right parenthesis.
In some cases, you need to use two quotes to tell that you want the character quote and that it is not the end of the string.
Don't know if it applies here, but maybe you could try.
Yes indeed, it is clearly a problem here. In Scilab 5, a string started
with " can be terminated with ' , and vice-versa. This tolerance is no
longer accepted with Scilab 6.
So here,

dos('grdinfo FAA.grd -C | gawk ""{nx=$10; ny=$11}; {print nx, ny}"" > nxy.txt','-echo')
must be used.

Samuel Gougeon
Lester Anderson
2015-12-04 08:40:11 UTC
Permalink
Thanks Samuel for the clarification. Adding the double quotes worked
fine. Will this work with single quotes in v6 as in the original
syntax?
Post by Lester Anderson
Hello,
De : Lester Anderson
Envoyé : jeudi 3 décembre 2015 16:56
dos('grdinfo FAA.grd -C | gawk "{nx=$10; ny=$11}; {print nx, ny}" >
nxy.txt','-echo')
!--error 3 Waiting for right parenthesis.
In some cases, you need to use two quotes to tell that you want the
character quote and that it is not the end of the string.
Don't know if it applies here, but maybe you could try.
Yes indeed, it is clearly a problem here. In Scilab 5, a string started with
" can be terminated with ' , and vice-versa. This tolerance is no longer
accepted with Scilab 6.
So here,
dos('grdinfo FAA.grd -C | gawk ""{nx=$10; ny=$11}; {print nx, ny}"" > nxy.txt','-echo')
must be used.
Samuel Gougeon
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
Samuel Gougeon
2015-12-04 09:29:02 UTC
Permalink
Post by Lester Anderson
Thanks Samuel for the clarification. Adding the double quotes worked
fine. Will this work with single quotes in v6 as in the original
syntax?
For the moment, 6.0 does not support inner simple unprotected ' or ",
but IMO it should, like in the PHP language.
Report just posted for that: http://bugzilla.scilab.org/14287

Samuel

Loading...