OS-COMMAND Fails Due to Windows Command-Line Parsing

I know I have seen the solution for this before, but I'll be darned if I can find it...

Windows does some funky parsing of command line parameters, requiring embedded quotes, tildas, etc. to pass a parameter that has embedded quotes from OS-COMMAND. Hoping somebody has the key.

Example:

l-db = "C:\My Folder\My Subfolder\My.db".
l-cmd = "C:\PROGRESS\OpenEdge\bin\prostrct repair " + l-db.

OS-COMMAND VALUE(l-cmd).

I've also tried:

l-db = "C:~"\My Folder~"\~"My Subfolder~"\My.db".
l-cmd = "C:\PROGRESS\OpenEdge\bin\prostrct repair " + l-db.

Neither seem to pass the entire pathname paramenter to prostrct.
Thanks in advance.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Other things to remember

some other common ideas:
use the SUBSTITUTE command to aid putting quotes or spaces in
use CHR(20)/CHR(34) (if I'm remembering the chrs correctly) to put spaces/quotes in
use the QUOTER function

DEF VAR cmd AS CHAR.
ASSIGN cmd = SUBSTITUTE('&1 &2 &3 &4 &3',
'my_prog',
QUOTER('C:\temp\My documents'),
CHR(34),
'hello').
MESSAGE cmd.
/* OS-COMMAND VALUE(cmd). */


alonb's picture

os-command on windows is

os-command on windows is notorious for having issues.

issues with quotes and certain characters, from where it's ran etc. etc.

win_batch( ) procedure (from the Progress STandard Libraries) was written mainly as replacement for os-command on windows.

win_batch( ) uses winapi and always works!

win_bacth( ) also supports multiple commands and can return the errorlevel.

{slib/slibwin.i}

run win_batch(
input 'proenv ~n'
+ 'cd C:\Progress\WRK\OpenEdge11 ~n'
+ 'prostrct repair sports2000',
input 'silent,wait' ).

if win_iErrorLevel <> 0 then
message "Error! " win_iErrorLevel skip.


Where can I download

Where can I download slib/slibwin.i?

Errol


libooxml + slib libraries

OE 10.2B05 Linux DB Windows Clients

you can get libooxml + slib libraries @ http://www.oehive.org/project/libooxml


alonb's picture

it's true that the OpenXML

it's true that the OpenXML Libraries for generating Word and Excel files on UNIX/Linux and Windows (slibooxml)

is based on the Progress STandard Libraries project (slib)

and also includes a *minimal* version of slib

http://www.oehive.org/project/libooxml

but to get the full version of the Progress STandard Libraries (slib)

download the version from the project home page

http://www.oehive.org/project/lib

thank you for trying our projects.

if you have any questions or requests feel free to contact me.

Alon Blich
+972-54-2188086
Skype: alon.blich
alonblich@gmail.com


Try OS-COMMAND

Try OS-COMMAND VALUE("C:\PROGRESS\OpenEdge\bin\prostrct repair ":U + QUOTER("C:\My Folder\My Subfolder\My.db":U)).


Thanks, but I need to be

Thanks, but I need to be able to substitute the database parameter programmatically (can't be a constant). When I replace "C:\My Folder\My Subfolder\My.db":U with l-db, I still get the same error.


works for me: DEFINE

works for me:

DEFINE VARIABLE cDB AS CHARACTER NO-UNDO.

ASSIGN
cDB = QUOTER("C:\develop\test directory\icfdb.db":U)
NO-ERROR.

OS-COMMAND VALUE("C:\PROGRESS\OpenEdge\bin\prostrct repair":U + cDB).

I would consider using the following:
DEFINE VARIABLE cOutput AS CHARACTER NO-UNDO.
DEFINE VARIABLE cDB AS CHARACTER NO-UNDO.

ASSIGN
cDB = QUOTER("C:\develop\test directory\icfdb.db":U)
NO-ERROR.

INPUT THROUGH VALUE("C:\PROGRESS\OpenEdge\bin\prostrct repair":U + cDB).

REPEAT :
IMPORT UNFORMATTED cOutput.
DISPLAY cOutput FORMAT "x(80)" WITH WIDTH 100.
END.


Almost

Getting there, but getting strange results. Your example is still not refactored for dynamic input, since you have hard-coded the DB path.
Here is my interpretation of your example.

Trial #1...

DEF VAR l-cmd AS CHAR NO-UNDO.
DEF VAR l-db AS CHAR NO-UNDO.

ASSIGN l-db = "C:\My Folder\db\Mydb":U.
ASSIGN l-db = QUOTER(l-db) NO-ERROR.
OS-COMMAND VALUE("C:\PROGRESS\OpenEdge\bin\prostrct repair":U + l-db).

This generates "PROSTRCT: too few arguments. (6910)
So, I added a space after "repair", as in
OS-COMMAND VALUE("C:\PROGRESS\OpenEdge\bin\prostrct repair ":U + l-db).
This generated...

Trial #2...
OpenEdge Release 10.2B as of Mon Dec 14 17:02:01 EST 2009

PROSTRCT REPAIR: cannot read file C:\My Folder\db\Mydb.st, command ignore
d. (6918)

C:\OpenEdge\WRK>

Notice the "C:\OpenEdge\Wrk" ... it seems like it is looking the OE working directory to find the db. The .db and all the other files (.d1, .lg, .st, .lg, .b1) are all in the correct folder.

Thanks for helping. If you are still interested in pursuing this, I'd appreciate it.


DEFINE VARIABLE cPath AS

DEFINE VARIABLE cPath AS CHARACTER NO-UNDO.
DEFINE VARIABLE cDB AS CHARACTER NO-UNDO.

ASSIGN
cPath = "C:\My Directory\My Db\"
cDB = QUOTER(cPath + "test":U).

OS-COMMAND VALUE("cd " + cPath + "& C:\develop\dlc101c\bin\prostrct repair ":U + cDB).


Correction

Sorry, the first line should have read "embedded blanks" (not quotes).


Thanks

Thanks so much. I have it working now!