4Utils, %_STARTUPCMD and spaces

#1
There is a minor problem with %_STARTUPCMD
It would be great tool to restart TCC, but:
if there is a space inside AGV0, ARGV0 is not quoted. So - to rebuild running command it is necessary to use ComSpec or _TCCPATH

Example:
[D:\P4\P Apps\PortableApps]echo %_STARTUPCMD
D:\P4\P Apps\PortableApps\TccLePortable\App\32\tcc.exe @"D:\P4\P Apps\PortableApps\TccLePortable\Data\settings\tcc.ini"

I would expect to get something like
"D:\P4\P Apps\PortableApps\TccLePortable\App\32\tcc.exe" @"D:\P4\P Apps\PortableApps\TccLePortable\Data\settings\tcc.ini"

Best regards.

BTW. It one of the most useful plugins :)
 
#2
_STARUPCMD is very simple minded.

Code:
INT WINAPI _STARTUPCMD ( WCHAR *psz )
{
   lstrcpy(psz, GetCommandLine());
   return 0;
}
I'm confident that if TCC's path had a space in it then the quoted path\filename would (have to) appear in the command line.

Code:
g:\tc16> "g:\tc16\a b\tcc.exe" /k echo foo

foo

g:\tc16> echo %_startupcmd
"g:\tc16\a b\tcc.exe" /k echo foo
How did you manage to start "D:\P4\P Apps\PortableApps\TccLePortable\App\32\tcc.exe" without argv[0] being quoted?
 
#4
That results in something rather odd here.
Code:
v:\> echo %COMSPEC
G:\TC16\a b\TCC.EXE

v:\> echo %_STARTUPCMD
"g:\TC16\a b\tcc.exe" @g:\tc16\TCMD.INI

v:\> echo %@Quote[%comspec]%@right[-%@Len[%COMSPEC],%_STARTUPCMD]
"G:\TC16\a b\TCC.EXE"e" @g:\tc16\TCMD.INI
 
#5
Probably you are trying to start third instance of the TCC, but second one got ARGV0 quoted, so %_STARTUPCMD is properly quoted (there is no need to reconstruct).

It was only the draft.
The first instance of 4TCC, started directly by explorer, got ARGV0 unquoted.
The first instance of 4TCC, started from cmd.exe, got ARGV0 quoted.
The second instance - got ARGV0 quoted.
So - if the leftmost character of %_STARTUPCMD is quote - %_STARTUPCMD can be used directly. Otherwise - use my formula.

-------------------

I've just understood the question :)
Try to create shortcut. Or use PortableApps launcher. Or start directly from explorer
 
#6
I've tried two of them. This was started from Explorer with a 2-click on tcc.exe while in "g:\tc16\a b".
Code:
g:\tc16\a b> echo %_STARTUPCMD
"G:\TC16\a b\tcc.exe"
And this was started from a shortcut.
Code:
v:\> echo %_STARTUPCMD
"G:\TC16\a b\tcc.exe" \q
In fact, if I specify a path with spaces in the shortcut's target, the quotes are automatically added to what I typed when I press "Apply" or "OK".

I can't imagine how windows will start a process whose EXE name contains spaces and is unquoted; I don't think it's possible. Can you give me exact steps to see a _STARTUPCMD where TCC's path contains spaces and is not quoted?
 
#7
It is a part of my own launcher.

At home I will try to extract essential code to recreate the case. To start tcc.exe I'm using
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
BOOL WINAPI CreateProcess(
_In_opt_ LPCTSTR lpApplicationName,
_Inout_opt_ LPTSTR lpCommandLine,
_In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ BOOL bInheritHandles,
_In_ DWORD dwCreationFlags,
_In_opt_ LPVOID lpEnvironment,
_In_opt_ LPCTSTR lpCurrentDirectory,
_In_ LPSTARTUPINFO lpStartupInfo,
_Out_ LPPROCESS_INFORMATION lpProcessInformation
);
where lpApplicationName is a path without quotes, but with spaces.
It is funny, CreateProcess doesn't allow quoted lpApplicationName.
 
#9
Found:

lpApplicationName=L"D:\\P4\\P Apps\\PortableApps\\TccLePortable\\App\\32\\tcc.exe"
lpCommandLine=L"D:\\P4\\P Apps\\PortableApps\\TccLePortable\\App\\32\\tcc.exe @\"D:\\P4\\P Apps\\PortableApps\\TccLePortable\\Data\\settings\\tcc.ini\""

lpApplicationName: is a string without quotes
lpCommandLine: begins with the same string.

tcc.exe parses it properlly, doesn't show any warnings

OS: Win7 proffesional, 64bit, up to date
Compiler: VS2013 Express
 
#10
You can also do this.
Code:
WCHAR szApp[64] = L"g:\\tc16\\a b\\tcc.exe";
 WCHAR szLine[64] = L"garbage /k echo foo";
 CreateProcess(szApp, szLine, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
and get this
Code:
p:\4utils\release> echo %_STARTUPCMD
garbage /k echo foo
So I think that if you get to specify what GetCommandLine() will return and you thing it should have quotes in it, then you should put the quotes in it.