[comp.sys.amiga] Problem with paths and Execute

phi@munnari.oz (Philip F. Hingston) (08/31/88)

	I've got this really neat C program that uses Execute() to run shell
scripts. It's nearly finished but I've come across a last minute hitch.
	When the program is run from a cli, the processes created by Execute()
inherit the search path from that cli. However, when run from the workbench,
they get the default search path ( CurrentDirectory + C: ). This is very
painful as I don't want to have to set a path for each process, possibly
causing "Please insert volume xxx" requesters and annoying the user.
	The program sys:cli seems to have some way of picking up the path that
was in effect when loadwb was run ( I think ).
	Can anyone tell me how to do this or suggest another solution to my
problem?

		Thanks in anticipation.		Philip Hingston
						(phi%munnari.oz@uunet.uu.net)

iphwk%MTSUNIX1.BITNET@cunyvm.cuny.edu (Bill Kinnersley) (09/02/88)

[In "Problem with paths and Execute()", "Philip F. Hingston" said:]
:
:     I've got this really neat C program that uses Execute() to run shell
: scripts. It's nearly finished but I've come across a last minute hitch.
:     When the program is run from a cli, the processes created by Execute()
: inherit the search path from that cli. However, when run from the workbench,
: they get the default search path ( CurrentDirectory + C: ).
:     The program sys:cli seems to have some way of picking up the path that
: was in effect when loadwb was run ( I think ).
:                         (phi%munnari.oz@uunet.uu.net)
:
Wow, this is a good example, including everything at once!  The answer
(just like all good questions) is 0, but let's show some work:

Proc1             Proc2               Proc3               Proc4

CLI
 :
LoadWB- - - - ->WorkBench- - - - - >MyProgram
 :                                      :
EndCLI                            Execute("foo")
                                        :
                                      C:RUN- - - - - ->Background CLI
                                                            :
                                                           foo
                                                            :
                                                        (suicide)

MyProgram, being launched from the WorkBench, becomes an independent process
Proc3, with no CLI.
The Execute() call makes a BSTR saying "foo", deposits this in Proc3's
pr_Result2 field, and chains to C:RUN.
RUN, finding the pr_Result2 field occupied, realizes it was called by
Execute().  It manufactures a new CLI in the background, and builds a
fake file handle for the cli_StandardInput containing the command "foo".

Each CLI has a Path stored in the field cli_CommandDir.  This is a linked
list of Locks, linked by BPTRs in fl_Link.  When a new CLI is created from
an old CLI, the Path is list-copied into the new CLI structure and thus
gets inherited.

In this case, Proc3 has no CLI, so Proc4's Path will be NULL.  By default
the CLI will only look for "foo" in the current directory (pr_CurrentDir)
and C:, and that's the behavior you are seeing.


--

Bill Kinnersley
  Physics Department            BITNET: iphwk@mtsunix1
  Montana State University      INTERNET: iphwk%mtsunix1.bitnet@cunyvm.cuny.edu
  Bozeman, MT 59717             CSNET: iphwk%mtsunix1.bitnet@relay.cs.net
  (406)994-3614                 UUCP: ...ucbvax!mtsunix1.bitnet!iphwk
"This message was packed as full as practicable by modern electronic
equipment.  Some settling of contents may have occurred during transmission."

phi@munnari.oz (Philip F. Hingston) (09/07/88)

	Sorry to bore you all by re-posting this. I posted this query a week or
so back. I got one very helpful reply from Bill Kinnersley ( thanks Bill ),
which explained very clearly what was happening. Since then I've tried some
unsuccessful experiments based on that explaination. Basically whenever I
try to tinker with my process's cli_CommandDir I get guru # 0000008.xxxxx .
I guess this means I aren't allowed to do that.
	So how does sys:cli do it??? I guess this query might be better
directed to comp.sys.amiga.tech but I don't have access. Thanks in advance
for any assistance.
	
>	I've got this really neat C program that uses Execute() to run shell
>scripts. It's nearly finished but I've come across a last minute hitch.
>	When the program is run from a cli, the processes created by Execute()
>inherit the search path from that cli. However, when run from the workbench,
>they get the default search path ( CurrentDirectory + C: ). This is very
>painful as I don't want to have to set a path for each process, possibly
>causing "Please insert volume xxx" requesters and annoying the user.
>	The program sys:cli seems to have some way of picking up the path that
>was in effect when loadwb was run ( I think ).
>	Can anyone tell me how to do this or suggest another solution to my
>problem?


						(phi%munnari.oz@uunet.uu.net)