I have looked at the answers already provided, but I'm still stuck. Here is what I currently have:
start "" "C:\Program Files (x86)\Spark\Spark.exe"
echo Spark started
This works fine. But now I want to pass parameters to the client, which must be wrapped in quotes. I can do the following on the command line:
"C:\Program Files (x86)\Spark\Spark.exe" "user=%USERNAME%&server=example.org"
And it starts up with the user and server fields filled in.
But when I try to edit the batch script to add those quote-wrapped parameters, I get a variety of errors depending on how I try to add double-quotes and where, etc.
So how would I add a quote-wrapped parameter to the start line?
Update:
I accidentally got it to work, but haven't been able to reproduce it. But it didn't work exactly right. The user name was still blank, but the server was filled in. I forgot to mention that I am using an environment variable for the user name: %USERNAME%
So it might be my problem is that I can't escape quotes and use environment variables?
Final Answer:
It turns out that part of the problem was that I was using the wrong parameter, but originally I had been using the right one, so I didn't notice. From the command line, I should have:
"C:\Program Files (x86)\Spark\Spark.exe" "username=%USERNAME%&server=example.org"
and so from the batch file, the following works:
start "" "C:\Program Files (x86)\Spark\Spark.exe" "username=%USERNAME%&server=example.org"
echo Spark started
Much thanks and points to dcp for getting me to the right answer.
Did you try this?
"C:\Program Files (x86)\Spark\Spark.exe" "\"user=foo&server=example.org\""
This worked when I tried a simple command line test and c++ program (I could see the quotes when I printed the argv[1] argument).
UPDATE:
If %USERNAME% has spaces in it, then you need to quote it like this (see below). I think you can remove the other quotes.
"C:\Program Files (x86)\Spark\Spark.exe" user="%USERNAME%"&server=example.org
Related
I'm in Windows 10 & I'm trying to open an app using start command which goes like:
start "C:\Program Files\MyElectronApp\MyElectronApp.exe" which opens the app as expected.
I also want to pass some arguments after the above-mentioned command such as:
start "C:\Program Files\MyElectronApp\MyElectronApp.exe" --UUID=762835745634 --org_token=r8347t89457
When I write this command, I get UUID as /prefetch:1 despite passing any thing, I tried adding double quotes "", but same issue. However, I manage to get org_token as expected. as shown in the screenshot.
What could be causing this issue?
What I tried to address the issue?
I tried to add double quotes for the value of UUID, then I tried to use powershell and git bash for the same thinking it could solve the issue. Then, I checked the prefetch folder only to find it's empty. Then, I changed the order of args, but nothing happened.
Here's how I solved it:
The args should NOT be in UPPERCASE, in this case it's UUID, I changed it to small case uuid. For windows uppercase args are reserved or fixed for some DOS-level stuff.
Just change:
start "C:\Program Files\MyElectronApp\MyElectronApp.exe" --UUID=762835745634 --org_token=r8347t89457
to
start "C:\Program Files\MyElectronApp\MyElectronApp.exe" --uuid=762835745634 --org_token=r8347t89457
The exact reason for this is not clear as I couldn't find one. Will certainly update this once I get to know the same.
Inside Vim on Windows, I'm trying to filter the lines in a file through a shell executable. I'm using the following command:
:0,$!sort
The idea being that I'll sort the lines of the file using the Windows sort command.
The issue is that I get nothing back so, effectively, all the lines in the file are deleted, i.e. they are replaced with nothing (I can recover all the lines using undo u).
Outside of Vim, the following command works fine:
type sort-lines.txt | sort
("sort-lines.txt" is the test file that I'm working with in vim.)
I've tried this with the Windows sort command as well as with the Cygwin sort command. The results are the same.
Interestingly, if I use the following command in Vim:
:0,$!dir
The lines of the file are replaced with the output from the dir command. This makes me think that the external program is executing, but it isn't correctly receiving the input lines from the file.
Is there something that needs to be adjusted in my configuration to make this work? I checked the value of Vim's shellpipe option and it is set to:
shellpipe=>%s 2>&1
which doesn't seem right to me.
Okay, I found the issue.
I had an Autorun CMD script set in my registry. Whenever vim would spin up CMD to run the filter, the Autorun script would run and somehow block the piped-in data from getting in.
To workaround the issue, I changed the value of the vim "shell" variable. Here is what I set it to.
:set shell=C:\Windows\system32\cmd.exe\ /d
The /d tells CMD not to run any Autorun scripts. The extra backslash after the "cmd.exe" is necessary in order to escape the space character between cmd.exe and the /d.
With this setting in place, filtering works correctly.
For a discussion of Autorun and the /d option see this MSDN article
Thanks, Darcy, for pointing me in the right direction. (BTW, you have a great last name.)
vim has a built-in sort utility. You can try that.
:0,$sort
I have a batch script setup to automatically retrieve a file from a remote FTP server. Part of the requirement is the file will be named with a new datestamp each day, such as "File_90611.csv." I have a command line tool that generates the filename; which is then supposed to be set to a variable using the line below:
for /f "delims=" %a in ('C:\BIN\YesterdayDateStamp.exe') do #set DATESTAMP=%a
The problem is this. This line works fine when run from the command line directly. However, when I put this exact same line in a batch script and run it; I get this error:
\BIN\YesterdayDateStamp.exe') was unexpected at this time.
I REM'ed everything out in the script except the FOR ... IN commands to make sure there wasn't some sort of conflict; but even with this I still get an error.
Been Googling for an answer but have no leads. Any ideas? Any constructive input is greatly appreciated.
Thanks,
Frank
When for is used in a batch file, you need to double the percent signs in front of the variable name.
From for /?:
To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.
This is probably batch scripting 101, but I can't find any clear explanation/documentation on why this is happening or if my workaround is actually the solution. So basically any terminology or links to good sources is really appreciated.
So I have a program I want to execute via batch script (along with several other programs). It's the only one where the exe is not in a Program Files folder. I can get it to start like this:
C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe
But I get an error along the lines of:
Run-time Error '3024':
Could not find file
C:\Users\MyUserName\Desktop\ModuleSettings.mdb
So it seems that the program is looking for its settings files from the same location that the batch script starts up. Given that I finally got everything to work by doing the following:
cd C:\WeirdProgram\WeirdProgramModule\
weirdmodule.exe
That works fine, and it's not the end of the world to have to go this route (just one extra line), but I've convinced myself that I'm doing something wrong based on lack of basic understanding.
Anybody know or can point me to why it works this way?
Oh, and doing the following:
start "C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe"
doesn't do anything at all.
Thanks,
you are doing it perfectly :-)
the executable is probably looking for this file in the "current working directory", which is being set, when you "cd" to it before.
you can set your working directory manually by creating a shortcut to your batch file; right click; properties.
edit:
you can also set your current working directory using the start command:
start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe"
edit:
If you like to pass params, just add them to the executable filename as you would in a regular shortcut:
start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe" "param1 param2"
or
start "Title" /D "C:\WeirdProgram\WeirdProgramModule\" "weirdmodule.exe param1 param2"
For reference, the syntax is described here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true.
What's happening is that weirdmodule.exe is looking in the "current directory" for the .mdb file. You might be able to tell it where to find the .mdb file through a command line parameter or some other configuration method (registry or .ini file maybe). How you'd specify the location is entirely up to the weirdmodule.exe program, though.
Other than that, your current workaround is probably what you're stuck with.
As far as your problem with using start.exe... the start.exe program has the very, very odd behavior (bizarre behavior in my opinion) of treating the first parameter as the 'title' to put in the window if (and only if) the first parameter is in quotes. So you have a couple of options:
Don't use quotes to specify the program. This works for you because you don't need quotes (there aren't any spaces or other special characters in the path that would require quoting it):
start C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe
Give an empty (or some other string) title as the first parameter. This is something you'd have to do if your path required quotes:
start "" "C:\WeirdProgram\WeirdProgramModule\weirdmodule.exe"
I need to create a batch file which starts multiple console applications in a Windows .cmd file. This can be done using the start command.
However, the command has a path in it. I also need to pass paramaters which have spaces as well. How to do this?
E.g. batch file
start "c:\path with spaces\app.exe" param1 "param with spaces"
Actually, his example won't work (although at first I thought that it would, too). Based on the help for the Start command, the first parameter is the name of the newly created Command Prompt window, and the second and third should be the path to the application and its parameters, respectively. If you add another "" before path to the app, it should work (at least it did for me). Use something like this:
start "" "c:\path with spaces\app.exe" param1 "param with spaces"
You can change the first argument to be whatever you want the title of the new command prompt to be. If it's a Windows app that is created, then the command prompt won't be displayed, and the title won't matter.
Escaping the path with apostrophes is correct, but the start command takes a parameter containing the title of the new window. This parameter is detected by the surrounding apostrophes, so your application is not executed.
Try something like this:
start "Dummy Title" "c:\path with spaces\app.exe" param1 "param with spaces"
start "" "c:\path with spaces\app.exe" "C:\path parameter\param.exe"
When I used above suggestion, I've got:
'c:\path' is not recognized a an internal or external command, operable program or batch file.
I think second qoutation mark prevent command to run. After some search below solution save my day:
start "" CALL "c:\path with spaces\app.exe" "C:\path parameter\param.exe"
Interestingly, it seems that in Windows Embedded Compact 7, you cannot specify a title string. The first parameter has to be the command or program.
You are to use something like this:
start /d C:\Windows\System32\calc.exe
start /d "C:\Program Files\Mozilla
Firefox" firefox.exe start /d
"C:\Program Files\Microsoft
Office\Office12" EXCEL.EXE
Also I advice you to use special batch files editor - Dr.Batcher
Surrounding the path and the argument with spaces inside quotes as in your example should do. The command may need to handle the quotes when the parameters are passed to it, but it usually is not a big deal.
I researched successfully and it is working fine for me. My requirement is to sent an email using vbscript which needs to be call from a batch file in windows. Here is the exact command I am using with no errors.
START C:\Windows\System32\cscript.exe "C:\Documents and Settings\akapoor\Desktop\Mail.vbs"