Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: frontCall and a more complicated script...  (Read 12532 times)
Sally W.
Posts: 32


« on: July 23, 2015, 04:14:26 pm »

Since it's not possible (it seems) with BDL running on a unix server to determine if a DOS or mapped path available to the GDC is a directory or a file, or is readonly or writeable, I am looking to run a more complicated script than the simple 'if exist' in my previous question.

The script in question from my batch file on the PC running the GDC:

Code
  1. @echo off
  2. set path=%1
  3.  
  4. for %%A in (%path%) do set X=%%~aA
  5.  
  6. set D=%X:~0,1%
  7. if %D% equ d (echo directory) else (echo file)
  8.  
  9. set R=%X:~1,1%
  10. if %R% equ r (echo readonly) else (echo writable)

Firstly I've put both checking for a directory and checking if writeable in the same script, in what I want to achieve there will be one to check if it's a directory and another to check if it's writeable.

Secondly this only works if the path exists, but I only intend calling it if that is the case.

My question is how do I format the command which is passed into frontCall to get the right syntax?  I am finding DOS very picky in unexpected ways...



Obviously it would need amending to return a true or false value as per my previous question, but
Reuben B.
Four Js
Posts: 1119


« Reply #1 on: July 29, 2015, 07:17:41 am »

My advice would be to keep the individual frontcalls simple, doing one thing e.g. exists, is it a directory, is it writable, and keep your logic in the 4gl code.

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Sally W.
Posts: 32


« Reply #2 on: July 29, 2015, 09:22:47 am »

That is what I intend - the last two lines are only there because I will be implemting a version with those instead once I can get telling me if it's a file or a directory working.  Ditto the echo off, and path = %1.  But I still have no idea about how frontCall treats the % signs which since I'm not a DOS script person are mysterious to me, nor how to deal with the newlines in my scrip when implementing it in frontCall


Code
  1. for %%A in (X:\path) do set X=%%~aA
  2. set D=%X:~0,1%
  3. if %D% equ d (echo directory) else (echo file)
Sally W.
Posts: 32


« Reply #3 on: August 10, 2015, 12:32:34 pm »

I got an alternative way of seeing if a path is a directory from another forum which works, and a  1-liner to see if the path is readonly which I can't get working through frontCall.

It has to be double quotes round the 'r', not single, and I think that's the problem.  I've tried single quotes round the command and various ways of escaping the double quotes so far to no avail.  Obviously it needs to use 'exit 0' and 'exit 1' in place of 'echo readonly' and 'echo writeable'.  I've taken out the 'at' signs which aren't needed for frontCall.

The code as given:
Code
  1. @for %%A in ("test") do @echo %%~aA|find /i "r">nul&&(@echo readonly)||(@echo writeable)

As build into a string for frontCall with single quotes round the command and double quotes round the 'r':

Code
  1. let l_cmd = SFMT( 'cmd /c ''for %%A in (%1) do echo %%~aA|find /i "r">nul&&(exit 1)||(exit 0)''', p_path)
  2. display l_cmd
  3. call ui.Interface.frontCall( "standard", "execute", [l_cmd, 1], [l_bool])
  4.    if l_bool then
  5. display " writeable"
  6. else
  7. display " readonly"
  8. end if

As run, it gives readonly regardless of if I give it a readonly or a writable path:

Code
  1. cmd /c 'for %A in (E:\Users\sallyw\Downloads\test1) do echo %~aA|find /i "r">nul&&(exit 1)||(exit 0)'
  2. readonly
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines