Shell script question (Windows OS)

Hi,

I’m working on a project in which code will call another exe file from the same file path as the main file. I figure out I need to use some Shell script to make it happen. However, I met a problem is the Shell seems can only run one line of script, but I need multiple lines. I’m in Windows platform.

Here is the script I hope to run in shell.

“cd /d c:\users\xyz\documents\project1”

as you can see, under folder c:\users\xyz\documents\project1\ there will be a exe file named “command.exe”

“command.exe /?”

command.exe /? will show some help info about this command. I use it here just as a demo, in real code case, I will pass the correct parameters here instead of “/?”

So, in my xojo code, I tried

Dim sh As New Shell sh.Execute("cd /d c:\\users\\xyz\\documents\\project1\\command.exe /?") msgbox sh.result sh.close
the code above doesn’t give me the result as I expeceted.

Then I tried

Dim sh As New Shell sh.Execute("cd /d c:\\users\\xyz\\documents\\project1\") sh.WriteLine("command.exe /?") msgbox sh.result sh.close
This won’t work either.

What should I do to make this work, should I use different script? I try those steps only because I did the same steps in Windows cmd box.

Thanks in advance.

You have a few options, but “&” might be all you need. This post might help:

http://stackoverflow.com/questions/8055371/how-to-run-two-commands-in-one-line-in-windows-cmd

If Kem’s plan does not work, write the commands into a batch file and run that.

PS. I’d be careful of calling anything “command.exe” - I would regard that as a very suspicious name, maybe a trojan command interpreter.

Also, to execute multiple commands on one line, you need to separate the commands with a semi-colon. But normally, to do something like this, I would create a .bat file with all the commands I want to run in it and execute that.

-Paul

In DOS if you are calling a batch file from a batch file use must put the word ‘call’ in front of the command or it will just exectute one command and exit.

Well, thank you all your reply. “&” is the issue. Another way I found is to quote the whole path. for example,

“c:\users\xyz\documents\project1\command.exe” /? will do the same thing.

so the codes could be

Dim sh As New Shell sh.Execute("""c:\\users\\xyz\\documents\\project1\\command.exe"" /?") msgbox sh.result sh.close