Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-05

Changing the directory of the invoking shell

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Rich Pasco

Can a Free Pascal program, compiled as a Win32 console application, change the current directory of the invoking shell? A Borland Pascal program can.

Consider the program CHD.PAS containing

  begin
    chdir('C:\TEMP');
  end.

compiled into CHD.EXE.

I want a console session where I invoke it at the command prompt to look like this:

C:\>CHD
C:\TEMP>

and indeed, if I compile CHD.PAS with Borland Pascal for DOS (16-bit) that is exacty what happens when I invoke it under the Windows 2000 shell CMD.EXE.

However, if I compile CHD.PAS under Free Pascal for Win32, then when I invoke it (also under CMD.EXE), it produces:

C:\>CHD
C:\>

In other words, it seems that while CHD may successfully chenge the current directory for its own internal purposes, that change is not propgated back to the shell from which it was invoked, as I want. Can I remedy that? How?

- Rich

Unknown author
to Rich Pasco

Date sent: Fri, 17 May 2002 09:33:10 -0700
From: Rich Pasco
To:
Subject: [fpc-pascal]Changing the directory of the invoking shell Send reply to:

Can a Free Pascal program, compiled as a Win32 console application, change the current directory of the invoking shell? A Borland Pascal program can.

.
.

BP program can do it under DOS, because both the shell and your program operate in one environment (one address space). This isn't true for Win32 (and other multi-tasking systems) - each program has its own address space, and the daughter process just inherits the settings of its parent at the moment of it's launch (but not vice versa, of course).

Show quoted text 14 lines
and indeed, if I compile CHD.PAS with Borland Pascal for DOS (16-bit) that is exacty what happens when I invoke it under the Windows 2000 shell CMD.EXE. However, if I compile CHD.PAS under Free Pascal for Win32, then when I invoke it (also under CMD.EXE), it produces: C:\>CHD C:\> In other words, it seems that while CHD may successfully chenge the current directory for its own internal purposes, that change is not propgated back to the shell from which it was invoked, as I want. Can I remedy that? How?

I suspect you can't. The reason why it works for DOS programs is a special hack for these within M$ WinXX; so it's a feature of M$ WinXX, not of either of the mentioned compilers. It _might_ work as you expect if you compile your program for GO32v2 target (but beware: you might encounter problems with GO32v2 programs running under Win2000 - there should be something about this in our FAQ).

Tomas

Alex
to Unknown author

Hello, All!

Pls, help me!

I'm busy last time with creating Dialog window with colored radio and check-Buttons under win32 FPC. How can I do it?

Big thnx. 4 help!

Best regards, Alex ----------------------------------------------------- killall -9 lamers:))
Ingmar Tulva
to Alex

There is a message sent to a control's parent window; not sure but it could be WM_CONTROLCOLOR or something.
Browse a Win32 API reference for something like this.

hope it helps,
Ingmar

------

"Salamanders can survive up to six hours outside a fire if regularly fed pepper" (Scamander 1927).