~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to macros/util/unix_g.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [rep,stat]=unix_g(cmd)
 
2
//unix_g - shell command execution 
 
3
//%Syntax
 
4
//rep=unix_g(cmd)
 
5
//%Parameters
 
6
// cmd - a character string
 
7
// rep - a column vector of character strings
 
8
//%Description
 
9
// cmd instruction (sh syntax) is passed to shell, the standard output 
 
10
// is redirected  to scilab variable rep.
 
11
//%Examples
 
12
// unix_g("ls")
 
13
//%See also
 
14
// host unix_x unix_s
 
15
//!
 
16
// Copyright INRIA
 
17
[lhs,rhs]=argn(0)
 
18
if prod(size(cmd))<>1 then   error(55,1),end
 
19
 
 
20
if MSDOS then
 
21
  tmp=strsubst(TMPDIR,'/','\')+'\unix.out';
 
22
  cmd1= cmd + ' > '+ tmp;
 
23
else
 
24
  tmp=TMPDIR+'/unix.out';
 
25
  cmd1='('+cmd+')>'+ tmp +' 2>'+TMPDIR+'/unix.err;';
 
26
end 
 
27
stat=host(cmd1);
 
28
select stat
 
29
case 0 then
 
30
  rep=read(tmp,-1,1,'(a)')
 
31
  if size(rep,'*')==0 then rep=[],end
 
32
case -1 then // host failed
 
33
  disp('host does not answer...')
 
34
  rep=emptystr()
 
35
else
 
36
  if MSDOS then 
 
37
        write(%io(2),'unix_g: shell error');
 
38
        rep=emptystr()
 
39
  else 
 
40
        msg=read(TMPDIR+'/unix.err',-1,1,'(a)')
 
41
        disp(msg(1))
 
42
        rep=emptystr()
 
43
  end 
 
44
end
 
45
if MSDOS then
 
46
  host('del '+tmp);
 
47
else
 
48
  host('rm -f '+tmp);
 
49
end