home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / workbench / c / run.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  2.1 KB  |  102 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: run.c,v 1.7 1997/01/27 00:22:37 ldp Exp $
  4.     $Log: run.c,v $
  5.     Revision 1.7  1997/01/27 00:22:37  ldp
  6.     Include proto instead of clib
  7.  
  8.     Revision 1.6  1996/10/24 15:32:26  aros
  9.     Fixed some warnings about int/ptr conversions
  10.  
  11.     Revision 1.5  1996/09/17 16:43:01  digulla
  12.     Use general startup code
  13.  
  14.     Revision 1.4  1996/09/13 17:52:11  digulla
  15.     Use IPTR
  16.  
  17.     Revision 1.3  1996/08/01 17:40:45  digulla
  18.     Added standard header for all files
  19.  
  20.     Desc:
  21.     Lang:
  22. */
  23. #include <exec/memory.h>
  24. #include <proto/exec.h>
  25. #include <dos/dosextens.h>
  26. #include <dos/dostags.h>
  27. #include <proto/dos.h>
  28. #include <utility/tagitem.h>
  29.  
  30. int main (int argc, char ** argv)
  31. {
  32.     STRPTR args[1]={ 0 };
  33.     struct RDArgs *rda;
  34.     BPTR in, out, shell;
  35.     STRPTR s1, s2, buf;
  36.     struct Process *process;
  37.     ULONG num;
  38.     LONG error=0;
  39.  
  40.     rda=ReadArgs("COMMAND/A/F",(IPTR *)args,NULL);
  41.     if(rda!=NULL)
  42.     {
  43.     error=RETURN_ERROR;
  44.     s1=s2=(STRPTR)args[0];
  45.     while(*s2++)
  46.         ;
  47.     buf=(STRPTR)AllocVec(8+s2-s1,MEMF_ANY);
  48.     if(buf!=NULL)
  49.     {
  50.         CopyMem("COMMAND ",buf,8);
  51.         CopyMem(s1,buf+8,s2-s1);
  52.         shell=LoadSeg("c:shell");
  53.         if(shell)
  54.         {
  55.         in=Open("CONSOLE:",MODE_OLDFILE);
  56.         if(in)
  57.         {
  58.             out=Open("CONSOLE:",MODE_NEWFILE);
  59.             if(out)
  60.             {
  61.             struct TagItem tags[]=
  62.             {
  63.                 { NP_Name, (IPTR)"Background task" },
  64.                 { NP_Arguments, 0 },
  65.                 { NP_Input, 0 },
  66.                 { NP_Output, 0 },
  67.                 { NP_Error, 0 },
  68.                 { NP_Seglist, 0 },
  69.                 { NP_Cli, 1 },
  70.                 { TAG_END, 0 }
  71.             };
  72.             tags[1].ti_Data=(IPTR)buf;
  73.             tags[2].ti_Data=(IPTR)in;
  74.             tags[3].ti_Data=(IPTR)out;
  75.             tags[5].ti_Data=(IPTR)shell;
  76.             Forbid();
  77.             process=CreateNewProc(tags);
  78.             if(process!=NULL)
  79.             {
  80.                 num=process->pr_TaskNum;
  81.                 out=in=shell=0;
  82.                 error=0;
  83.             }
  84.             Permit();
  85.             Close(out);
  86.             if(process&&VPrintf("[CLI %ld]\n",&num)<0)
  87.                error=RETURN_ERROR;
  88.             }
  89.             Close(in);
  90.         }
  91.         UnLoadSeg(shell);
  92.         }
  93.         FreeVec(buf);
  94.     }
  95.     FreeArgs(rda);
  96.     }else
  97.     error=RETURN_FAIL;
  98.     if(error)
  99.     PrintFault(IoErr(),"Run");
  100.     return error;
  101. }
  102.