Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

problem about batch file and DOS window

Posted on 2002-03-06
10
237 Views
Last Modified: 2010-04-05
Hi,
My program call a batch file at runtime.
The batch file like:

D
cd D:\Delphi
someapplication parameter
ren *.abc *.edf

The question is
1)
After I call the batch file, I found the *.abc files didn't renamed to *.edf files. The *.abc are in the D:\Delphi dir.

2)
I used to be able to see the DOS window after called and executed the batch file, but now I  could not to see it because it auto closed after running the batch file.


Peter
0
Comment
Question by:petershaw8
  • 2
  • 2
  • 2
  • +2
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6843893
to 1.

D:     <- look at the :
cd D:\Delphi
someapplication parameter
ren *.abc *.edf

if someapplication also a batchfilr then use
call someapplication parameter

to 2.

use winexec

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6843894
appendix to 1

D:     <- look at the :
cd \Delphi    <- no drive char
someapplication parameter
ren *.abc *.edf

0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6844288
Also, if you want to see the window, add the command "pause" as the very last one. This will wait for a keypress after the batch file was processed.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 6847832
Don't use WinExec since it's not supported anymore with Windows XP!

I repeat: Don't use WinExec since it's not supported anymore with Windows XP!
0
 

Author Comment

by:petershaw8
ID: 6849920
Hi,
D:
cd D:\Delphi
someapplication parameter
ren *.abc *.edf
Pause

I add the pause at the end.
The ren not works and the DOS window still shut down automatically.

peter
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 6850401
One tip... Why not use this:

D:
cd D:\Delphi
someapplication parameter
ren D:\Delphi\*.abc *.edf
Pause

The Rename command doesn't move files to another folder. It just renames the files. I think that someapplication changes the current folder before the batch file returns.
0
 
LVL 2

Expert Comment

by:gallaghe
ID: 6850417
Concerning the REN, place the path in front of the *.abc as shown below. If this does not work there is something very strange going on.

D:
cd D:\Delphi
someapplication parameter
ren D:\Delphi\*.abc *.edf
Pause


Concerning the PAUSE not working, try creating a shortcut for the batch file, in the property window try unchecking the "Close windows when finished" so that even if there is no PAUSE the window will stay open. If this helps then you could change the batch file to

@Echo Off
cls
D:
cd D:\Delphi
someapplication parameter
ren D:\Delphi\*.abc *.edf
Pause
cls

Usually the last cls will force a closing of the window. The secert is the first two lines.

Hope this helps




0
 

Author Comment

by:petershaw8
ID: 6854308
Hi,

Thank u for your help.
I will test the code below although I know someapplication does not change dir.

D:
cd D:\Delphi
someapplication parameter
ren D:\Delphi\*.abc *.edf

In window 2000 proessional, I could not find the "Close windows when finished"  option. In window 98 I delete the shortcut file *.pif, but the window was still auto closed. By the way, now how can I make the shortcut for the batch window?

Peter
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6854311
Er.... Try this:

@Echo Off
cls
D:
cd D:\Delphi
call someapplication parameter
ren D:\Delphi\*.abc *.edf
Pause
cls
0
 
LVL 2

Accepted Solution

by:
gallaghe earned 200 total points
ID: 6861271
Here is a quickie example for making a shortcut for a DOS batchfile.

program MyDemo;
uses
  Windows,
  Forms,
  Classes,
  ShlObj,
  ActiveX,
  ComObj,
  SysUtils,
  Dialogs,
  ShellAPI;

{$R *.RES}

const
  MyLinkName = 'kg_MyTest.lnk';
  MyPifName  = 'kg_MyTest.pif';  

procedure CreateLink(Target,Args,WorkDir,ShortCutName: String) ;
var
  IObj    : IUnknown ;
  Link    : IShellLink ;
  IPFile  : IPersistFile ;
  TargetW : WideString ;
begin
  IObj    := CreateComObject(CLSID_ShellLink) ;
  Link    := IObj as IShellLink ;
  IPFile  := IObj as IPersistFile ;

  with Link do
  begin
    SetPath(PChar(Target)) ;
    SetArguments(PChar(Args)) ;
    SetShowCmd(SW_SHOWNORMAL) ;
    SetWorkingDirectory(PChar(WorkDir)) ;
  end;
  TargetW := ShortCutName ;
  IPFile.Save(PWChar(TargetW),False) ;
end;

begin
  CoInitialize(nil) ;  { Needed this, usually goes in Initialization }
  with TStringList.Create do
  begin
    Add('@Echo Off') ;
    Add('Cls') ;
    Add('Echo Hello') ;
    Add('Echo.') ;
    Add('Pause') ;
    Add('Cls') ;
    SaveToFile('C:\MyTest.bat') ;
    Free ;
  end ;

  try
    { Create the ShortCut }
    CreateLink('C:\MyTest.bat','', 'C:\', 'C:\' + MyLinkName);
    CoUninitialize; { Usually in Finalization section of a form }

    ShellExecute(0,nil, PChar('C:\' + MyPifName),nil,nil,SW_NORMAL) ;
  except
    MessageDlg('Failed to locate ShortCut',mtError,[mbOk],0);
    CoUninitialize;
    Halt(3);  { Failed to create shortcut }
  end;
end.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 238
Virtuailstring tree compare node issue 14 125
code issue 8 153
Downloading email attachments 2 79
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question