1

I'm used to using a Mac, and I've written a program for my Mac that I now need to implement on a PC. On a mac, I run it through a shell file, using the following code:

cd ./desktop/Program
./MyProgram
./clearFiles

I've tried entering

cd ./desktop/Program^
./MyProgram^
./clearFiles

and saving it as both a .bat and a .cmd file but I can't get either to work. Is there a similar format to .sh I could use on Windows 7 to do the same thing? I want to be able to execute 3 commands in Command Prompt with just one click.

Jim Lewis
  • 43,505
  • 7
  • 82
  • 96
awerchniak
  • 357
  • 3
  • 16
  • 1
    What's with the caret? A .bat file should work fine even with just regular line endings between the commands (though the semantics of e.g. `cd` are different than on U*x). – tripleee Aug 18 '15 at 16:52
  • 1
    syntax is different when you do cmd batch files, also the folder structure – Carlos487 Aug 18 '15 at 16:52
  • When I don't include the carets, the .bat file only executes the first command and then quits (An answer to a similar question suggested the carets, but I couldn't get it to work). I want the .bat file to execute all three of those commands. – awerchniak Aug 18 '15 at 16:53
  • you might want to review Window 7 directory structure: http://www.informatics.buzdo.com/p737-windows-7-folders-files.htm – scrappedcola Aug 18 '15 at 16:54
  • 1
    Do you want to learn [tag:batch] or want to use [tag:unix] on windows enviroment? – gmo Aug 18 '15 at 17:03

1 Answers1

1

Microsoft offers a command-line reference.

It looks like you want to set current directory to a subdirectory on desktop of user containing your applications MyProgram and clearFiles which are called one after the other.

A batch file to do this would be:

cd /D "%USERPROFILE%\Desktop\Program"
MyProgram.exe
clearFiles.exe

As a single line the command line would be:

cd /D "%USERPROFILE%\Desktop\Program" & MyProgram.exe & clearFiles.exe

See Conditional Execution on SS64 containing even more information than provided by Microsoft about command processor of Windows.

Opening on Windows a command prompt window and executing help shows a list of commands. Running a command like cd with parameter /? in command prompt window results in getting help for this command displayed which can be multiple display pages like for commands for or set.

%USERPROFILE% references the environment variable USERPROFILE containing path to user profiles directory (home directory of user on *nix).

Mofi
  • 46,139
  • 17
  • 80
  • 143