ScriptBasic
Support => General Discussions => Topic started by: timm on September 17, 2008, 07:56:21 PM
-
When I attempt to use the execute command I get the following error "(0): error &H1:Not enough memory"
For example the following code will cause the error.
a = execute ("dir /b > list.txt", -1, pid)
Any suggestions would be appreciated, this is a real sumbling block for me.
-
almost as soon as I posted this I discovered the solution, the following code works fine.
a = execute ("cmd /c dir /b > list.txt", -1, pid)
any way hopefully I will save some one some frustration.
-
Thanks Tim for the report on how you solved your problem.
Posting issues/solutions here helps others traveling the same road.
John
-
Ok, my problem isn't solved after all. I guess I found a poor work around, not a solution. The following code does produce the (0): error &H1:Not enough memory error.
a = execute("cmd /c attrib newtest.sb > tempattrib.txt" , -1, pid)
the only solution I can think of at the moment, would be to write the commands out as batch files and execute them that way, but I really don't want to, its just so cludgy
Interestingly the command does execute in isolation, so it must be using just a LITTLE to much memory the program that it executes in is less than 40 lines of code and doesn't do anything extreme with strings or arrays.
This is driving me nutz
-
Hi Timm,
I remember having an issue with redirects with execute under Linux where it would output to the screen instead of a file. I mentioned it to Peter and ended up using a shell script that called scriba and did the redirect stuff in a script.
I will give it a try under Windows and see if I can reproduce your problem. There may be a issue with execute and shell redirection and should be reported in the bug tracker.
John
-
Timm,
I just tried your execute command on my Windows XP box and it worked fine.
Note: only line in program.
a = execute ("cmd /c dir /b > list.txt", -1, pid)
The list.txt file contained the directory contents (filenames only)
What version of ScriptBasic are you using?
My test was with the 2.1 version.
John
-
I am using ver. 2.1 compiled on 2/16/05
I can get it to execute in isolation, but can't get it to work in anything more elaborate than "hello world"
Here is the specific code, its really not much
function grabFhandle
if isundef(lastHandle) or lastHandle >= 512 then
lastHandle = 1
else
lastHandle += 1
end if
grabFhandle = lastHandle
end function
function fileAttribute(dname)
local fHandle
fHandle = grabFhandle()
a = execute("cmd /c attrib " + dname + " > tempattrib.txt" , -1, pid)
open "tempattrib.txt" for input as fHandle
line input #fHandle, oneline
close #fHandle
fileAttribute = left(oneline, 5)
end function
function test
local fHandle
fHandle = grabFhandle()
a = execute ("cmd /c dir /b > list.txt", -1, pid)
open "list.txt" for input as fHandle
x = 0
line input #fHandle, oneDir
do
dirArray[x, 1] = oneDir
dirArray[x, 2] = fileAttribute(oneDir)
print dirArray[x, 2], "\n"
x = x + 1
line input #fHandle, oneDir
loop until eof(1)
close #fHandle
print "lbound = ", lbound(dirArray), " ubound = ", ubound(dirArray), "\n"
for x=lbound(dirArray[]) to ubound(dirArray[])
print dirArray[x,1]
next
end function
dummy = test()
I can make run just by commenting out line 13
a = execute("cmd /c attrib " + dname + " > tempattrib.txt" , -1, pid)
I had been erroring on line 23 when it was written like this:
a = execute ("dir /b > list.txt", -1, pid)
but then I changed it to
a = execute ("cmd /c dir /b > list.txt", -1, pid)
and it started working
-
Timm,
You can use FREEFILE() to return the next available file handle.
fhandle = FREEFILE()
You can just close the file when your done and reuse the file handle again if you want.
I think your making this harder then it needs to be.
Check out the ScriptBasic wiki for directory open & close and the nextfile command to get the next file. (optionally based on a pattern)
http://www.scriptbasic.org/wiki/index.php?title=ScriptBasic:UsersGuide_12.14
This way you don't need the execute() at all.
Here is a bit of code I snagged from my MLS utility that removes old photos of properties that have gone off market. My directory structure is made up of 1000 sub-directories numbered from 000 to 999. The last three digits of the MLS # determines which sub-directory the photo(s) resides in. The following code would read all 1000 directories selecting only .jpg files and print the file names.
OPTIONS
- SbCollectDirectories Collect the directory names as well as file names into the file list.
- SbCollectDots Collect the virtual . and .. directory names into the list.
- SbCollectRecursively Collect the files from the directory and from all the directories below.
- SbCollectFullPath The list will contain the full path to the file names. This means that the file names returned by the function NextFile will contain the directory path specified in the open directory statement and therefore can be used as argument to file handling commands and functions.
- SbCollectFiles Collect the files. This is the default behavior.
- SbSortBySize The files will be sorted by file size.
- SbSortByCreateTime The files will be sorted by creation time.
- SbSortByAccessTime The files will be sorted by access time.
- SbSortByModifyTime The files will be sorted by modify time.
- SbSortByName The files will be sorted by name. The name used for sorting will be the bare file name without any path even if the option bit SbCollectPath is specified.
- SbSortByPath The files will be sorted by name including the path. The path is the relative to the directory, which is currently opened. This sorting option is different from the value sbSortByName only when the value sbCollectRecursively is also used.
- SbSortAscending Sort the file names in ascending order. This is the default behavior.
- SbSortDescending Sort the file names in descending order.
- SbSortByNone Do not sort. Specify this value if you do not need sorting. In this case directory opening can be much faster especially for large directories.
Note: Use AND if more then one option is needed with the OPEN DIRECTORY directive.
Hope this helps.
fn = FREEFILE
FOR D = 0 TO 999
DName = FORMAT("%~000~",D)
OPEN DIRECTORY DName PATTERN "*.jpg" OPTION sbCollectFiles AS #fn
RESET DIRECTORY #fn
GOSUB READ_DIR
CLOSE DIRECTORY #fn
NEXT D
END
READ_DIR:
FName = NEXTFILE(FN)
IF FName = undef THEN RETURN
PRINT Fname & "\n"
GOTO READ_DIR
John