Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Passing (too) long parameters to a batch file

- - - - - batch bat batchfile

  • Please log in to reply
11 replies to this topic

#1
diamant

diamant

    Newbie

  • Member
  • 46 posts
  • Joined 27-July 09
  • OS:98SE
  • Country: Country Flag

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?)




How to remove advertisement from MSFN

#2
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,847 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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.mozil...yurl-generator/

 

jaclaz 



#3
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,575 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

My recollection is that the OS has a 256 character limit whilst command.com has a 126 character limit.

#4
diamant

diamant

    Newbie

  • Member
  • 46 posts
  • Joined 27-July 09
  • OS:98SE
  • Country: Country Flag
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: Attached File  fire.bat.ERROR.png   2.07KB   0 downloads
If I change the content of fire.bat for test to

D:\Programme\Mozill~2\firefox.exe -print "http://www.google.de...zenz 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?!

#5
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,847 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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 OFF
ECHO "%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 OFF
ECHO %1
PAUSE

What happens?

 

jaclaz



#6
jumper

jumper

    2014 All-American Masters HJ'er

  • Member
  • PipPipPipPip
  • 507 posts
  • Joined 21-January 11
  • OS:98SE
  • Country: Country Flag
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, 02 April 2014 - 03:54 PM.

Design feedback requested:
IHAtool - IpHlpApi tester; call various functions and report results
--status-> framework is solid; 22 api's fully supported; preview release coming soon
ComDlg32 wrapper - ComDlgEx meets IpHlpApi wrapper
--status-> PrintDlgExW working in latest SumatraPDF 8^)
Future projects: ImportPatcher40 - dialog interface; Kexter - IP40+Ktree+Kexstubs

#7
diamant

diamant

    Newbie

  • Member
  • 46 posts
  • Joined 27-July 09
  • OS:98SE
  • Country: Country Flag

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

@ECHO OFF
ECHO "%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 OFF
ECHO 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+gefiltert
PAUSE 
then I get the following output:
Attached File  fire.bat.OUTPUT.png   5.83KB   0 downloads
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.

#8
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,847 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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 OFF
ECHO 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 fine
ECHO.
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, 04 April 2014 - 12:20 PM.


#9
jumper

jumper

    2014 All-American Masters HJ'er

  • Member
  • PipPipPipPip
  • 507 posts
  • Joined 21-January 11
  • OS:98SE
  • Country: Country Flag

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
Design feedback requested:
IHAtool - IpHlpApi tester; call various functions and report results
--status-> framework is solid; 22 api's fully supported; preview release coming soon
ComDlg32 wrapper - ComDlgEx meets IpHlpApi wrapper
--status-> PrintDlgExW working in latest SumatraPDF 8^)
Future projects: ImportPatcher40 - dialog interface; Kexter - IP40+Ktree+Kexstubs

#10
diamant

diamant

    Newbie

  • Member
  • 46 posts
  • Joined 27-July 09
  • OS:98SE
  • Country: Country Flag

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 OFF
ECHO 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 fine
ECHO.
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:Attached File  TestECHO.png   6.51KB   0 downloads

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?



#11
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,847 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
My bad. :blushing:
The &, && and || operators have been seemingly introduced in OS/2's (please read as NT's) CMD.EXE.
http://books.google....persand&f=false

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

jaclaz

Edited by jaclaz, 07 April 2014 - 03:55 AM.


#12
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,575 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

If the problem is that the URL exceeds the 126 character limit, have you considered using a URL shortening service?





Also tagged with one or more of these keywords: batch, bat, batchfile

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users