Jump to content

Passing (too) long parameters to a batch file


diamant

Recommended Posts

While trying to write an extension for firefox 3 for Win98SE it's needed for me to include a certain *.bat-file (or directly execute command.com). I'm running into problems with long parameters/arguments to pass.

I will explain the problem with a more simple example:

I have a *.bat-file

C:\notepadtest.bat

with following content:

c:\windows\notepad "%1"

Furthermore I have a *.txt-file

C:\testfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfile\testfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfile\test.txt

with content test (the content of the *.txt-file plays no role).

If I now try to execute

C:\notepadtest.bat C:\testfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfile\testfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfile\test.txt,

so it will not work! :blink: . (It will be shown a stupid error message instead of executing notepadtest.bat.)

It has definitely to do with the (very) long parameter

C:\testfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfile\testfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfiletestfile\test.txt.

With shorter parameters the notepadtest.bat works correctly. But long parameters (concretely: URLs) would later be needed for the firefox extension.

Is there any known way to pass long parameters into a *.bat-file?

(Or alternatively to pass long parameters directly to c:\windows\command.com, using the /k commandline option?)

Link to comment
Share on other sites


Why don't you post (as opposed to a "dummy" example) the actual thing that you are trying and the actual error you are getting (stupid as it might be)?

We are talking of the Windows 98 COMMAND.COM, right?

It is likely that you are hitting into one of the various limits to either PATH length or command line length (typically 127 or 255 characters if I recall correctly).

If it's a URL, maybe you can use a shortened url, like tinyurl or similar, since you mentioned firefox extension:

https://addons.mozilla.org/it/firefox/addon/tinyurl-generator/

jaclaz

Link to comment
Share on other sites

Yes, I mean the Win98SE command.com.

Yes, the problem concerns too long URLs.

I have the following code in one of my extension files:

function progstart(exe, parameters) {

if (!parameters || !parameters.length) parameters = [];

var datei = Components.classes["@mozilla.org/file/local;1"]

.createInstance(Components.interfaces.nsILocalFile);

datei.initWithPath(exe);

var proz = Components.classes["@mozilla.org/process/util;1"]

.createInstance(Components.interfaces.nsIProcess);

proz.init(datei);

proz.run(false, parameters, parameters.length);

}

function FirefoxPrintA() {

var a = "/k firefox -print " + gBrowser.currentURI.spec + " -printfile C:\zzw.png";

progstart('C:\\windows\\command.com', [a]);

}

function FirefoxPrintB() {

var c = gBrowser.currentURI.spec;

progstart('C:\\fire.bat', [c]);

}

I tried to use either function FirefoxPrintB or FirefoxPrintA. Both work fine while the URL got by gBrowser.currentURI.spec is not long.

If I use FirefoxPrintB I additionally use a file called fire.bat with following content:

D:\Programme\Mozill~2\firefox.exe -print "%1" -printfile C:\zzw.png

The mentioned error message looks (in german) like this: post-254155-0-78636900-1396432390_thumb.

If I change the content of fire.bat for test to

D:\Programme\Mozill~2\firefox.exe -print "http://www.google.de/search?hl=de&as_q=dos+command.com+long+parameters&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=&as_occt=&safe=images&as_filetype=&as_rights=nicht+nach+Lizenz+gefiltert" -printfile C:\zzw.png

so it works (with the long URL you can see). I can see in the "DOS-Box" after executing fire.bar that the whole URL is inserted.

So I think it must be a problem while copying(?) the URL to "%1" in the first version of fire.bat.

Possibly I should try to copy the URL directly into fire.bat, i.e. change fire.bat, while executing the firefox extension?!

Link to comment
Share on other sites

The "long" url, besides it's length, contains a number of "special" characters, namely the ampersand "&", that are likely to not play well.

I mean, temporarily try a "fire.bat" as following:

@ECHO OFFECHO "%1"PAUSE

What happens?

Can you wrap the parameter in double quotes before?

Something *like*:

function FirefoxPrintB() {
var c = gBrowser.currentURI.spec;
progstart('C:\\fire.bat', "[c]");
}

and try with this "fire.bat":

@ECHO OFFECHO %1PAUSE

What happens?

jaclaz

Link to comment
Share on other sites

It would nice if Firefox supported @params, but then it doesn't seem to support -print or -printfile either. :(

There is an extension for printing, maybe there's one for an argument file as well?

You could try "-print file:///C:/temp.htm" where temp.htm contains a meta refresh to the full URL:

<meta http-equiv="Refresh" content="0; URL=http://google.com">
Edited by jumper
Link to comment
Share on other sites

I mean, temporarily try a "fire.bat" as following:

@ECHO OFFECHO "%1"PAUSE
What happens?

Principially the same error like if I try to print. Several (long) URLs are not passed(?) correctly to the command line, shorter "easier" URLs are passed correctly.

It is not (only?) a problem with "special" characters, because I get the same error, if I manually produce a long URL *without* special characters, like

C:\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\test.txt,

open this with firefox and then try to start my extension. It is not shown correctly in command line.

Can you wrap the parameter in double quotes before?

I tried several versions with quotes; no success. It seems that the parameters must be completely inside the delimiters [].

If I use following fire.bat:

@ECHO OFFECHO http://www.google.de/search?hl=de&as_q=kommandozeilen+interpreter+win98&as_epq=127+zeichen&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=&as_occt=&safe=images&as_filetype=&as_rights=nicht+nach+Lizenz+gefiltertPAUSE 
then I get the following output:

post-254155-0-99950700-1396632897_thumb.

You can see that the (long!) example URL contents many special characters, which are shown correctly in the command line output.

So in my opinion it is obviously the problem how to get the URL variable, "created" as String with the command gBrowser.currentURI.spec, to the command line.

Maybe I should find another way to get the URL "outside" of firefox, e.g. into a temp *.txt file. But for that I would need also the command line...?!

There is an extension for printing, maybe there's one for an argument file as well?

I already use this extension; "my" extension is actually based on it.

You could try "-print file:///C:/temp.htm" where temp.htm contains a meta refresh to the full URL:

Doesn't work. It will be printed the first page which firefox "sees" when accessing C:/temp.htm, and this is a blank page. Maybe it could work if firefox somehow "waits" some seconds before printing.
Link to comment
Share on other sites

Allow me to doubt :unsure: that that screenshot is the result of running the batch you posted, unless you have a *somehow* non-standard command processor. :w00t:
Try running this batch:

@ECHO OFFECHO The following line is OK:ECHO "This line contains an ampersand & inside double quotes and is ECHOed fine"ECHO.ECHO The following line is OK:ECHO This line contains an ampersand ^& since it is escaped is ECHOed fineECHO.ECHO The following one it is NOT:ECHO This line contains an ampersand & will produce an error when ECHOed

You should get a result similar to this (your error message will be in German instead of Italian):

The following line is OK:
"This line contains an ampersand & inside double quotes and is ECHOed fine"

The following line is OK:
This line contains an ampersand & since it is escaped is ECHOed fine

The following one it is NOT:
This line contains an ampersand
"will" non è riconosciuto come comando interno o esterno,
un programma eseguibile o un file batch.

I don't think there are differences when it comes to the "&" character in cmd.exe vs. command. com.

With a "long" url containing an ampersand you are hitting 2 (two) different limits.
One is the length limit (and this is independent from the special characters).
One is the "special characters.

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

You could try "-print file:///C:/temp.htm" where temp.htm contains a meta refresh to the full URL:

Doesn't work. It will be printed the first page which firefox "sees" when accessing C:/temp.htm, and this is a blank page. Maybe it could work if firefox somehow "waits" some seconds before printing.
When the delay is zero, the page load isn't complete until after the meta refresh. Perhaps you have meta refresh disabled in Options? Put some extra text before the meta tag and also try -print "file:///C:/temp.htm" to make sure temp.htm is getting loaded.

This should also work for temp.htm, but requires javascript to be enabled:

<script>document.location="http..."</script>

You could also write the URL into pref.js at

user_pref("browser.startup.homepage", "http...");
Make sure that When Firefox starts: Show my homepage [no user_pref("browser.startup.page", 0);]

Then launch Firefox:

D:\Programme\Mozill~2\firefox.exe -print -printfile C:\zzw.png

Link to comment
Share on other sites

Allow me to doubt :unsure: that that screenshot is the result of running the batch you posted,

I just now tried to reproduce the output...

With exactly the same result which I yet posted!

Maybe we have different settings to execute batch files, or different versions of command.com?!

Some modifications/notifications on my Win98 system which I can remember on the fly:

I have here

- Win98SE, version 4.10.2222A

- actually KernelEx v4.5.2 installed

- updated unicows.dll, version 1.1.3790.0

Try running this batch:

@ECHO OFFECHO The following line is OK:ECHO "This line contains an ampersand & inside double quotes and is ECHOed fine"ECHO.ECHO The following line is OK:ECHO This line contains an ampersand ^& since it is escaped is ECHOed fineECHO.ECHO The following one it is NOT:ECHO This line contains an ampersand & will produce an error when ECHOed

I saved it as echo.bat and started it by double-clicking on it.

Following output:post-254155-0-90667200-1396856858_thumb.

For some (for me unknown) reason the ampersand seems (here) not to produce an issue, contrary to your output.

Could anybody other test one of the posted *.bat-files?

Link to comment
Share on other sites

My bad. :blushing:

The &, && and || operators have been seemingly introduced in OS/2's (please read as NT's) CMD.EXE.

http://books.google.it/books?id=CbsaONN5y1IC&pg=RA1-PA306&lpg=RA1-PA306&dq=DOS+command.com+ampersand&source=bl&ots=Cu3a0M5owZ&sig=gPrHuBNKkbGwGVGO5UHZun1trwM&hl=it&sa=X&ei=xHNCU_y4OqX9ywONqoCwBA&ved=0CDQQ6AEwATiqAQ#v=onepage&q=DOS%20command.com%20ampersand&f=false

So, your only "limit" seem to be the length of the string.

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...