Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Can't write to text file? (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: MS SQL Server in RB
Next thread: IPC or TCP socket?


Re: ConsoleApp and ServiceApp   -   Rubber Chicken Software Co.
  Can't write to text file?   -   Tim Jones
   Re: Can't write to text file?   -   Tim Jones
   Re: Can't write to text file?   -   Charles Yeomans
   Re: Can't write to text file?   -   Tim Jones
   Re: Can't write to text file?   -   Markus Winter
    Re: Can't write to text file?   -   Tim Jones
   Re: Can't write to text file?   -   fargo rpgportland.com

Can't write to text file?
Date: 02.08.09 18:22 (Sun, 2 Aug 2009 10:22:08 -0700)
From: Tim Jones
Hi Folks,

I'm trying to write the contents of a string constant out to a
temporary file. I'm using the following code in a method:

Dim theShell As New Shell
Dim theScript As String
Dim f As FolderItem
Dim tos As TextOutputStream

theShell.Execute "mktemp /tmp/keyscript.XXXXXX"
theScript = NthField(theShell.ReadAll, EndOfLine, 1) // just get
the file and path

f = GetFolderItem(theScript)
If f.Exists And f.IsWriteable Then
tos = f.AppendToTextFile // file exists from mktemp call above

tos.Write kKeyGenScript
tos.WriteLine
tos.Flush

tos.close
tos = Nil
Else
MsgBox "tempfile creation failed"
End If

However, after executing the code, the temp file exists and there are
no errors with the f or tos assignments, but the file is empty.

I've double checked the constant and it is properly defined and
marked as global.

Any ideas?

Thanks,
Tim

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Can't write to text file?
Date: 02.08.09 21:19 (Sun, 2 Aug 2009 13:19:02 -0700)
From: Tim Jones
On Aug 2, 2009, at 12:58 PM, Charles Yeomans wrote:

> On Aug 2, 2009, at 1:22 PM, Tim Jones wrote:
>
>> Hi Folks,
>>
>> I'm trying to write the contents of a string constant out to a
>> temporary file. I'm using the following code in a method:
>>
>> Dim theShell As New Shell
>> Dim theScript As String
>> Dim f As FolderItem
>> Dim tos As TextOutputStream
>>
>> theShell.Execute "mktemp /tmp/keyscript.XXXXXX"
>> theScript = NthField(theShell.ReadAll, EndOfLine, 1) // just get
>> the file and path
>>
>> f = GetFolderItem(theScript)
>> If f.Exists And f.IsWriteable Then
>> tos = f.AppendToTextFile // file exists from mktemp call above
>>
>> tos.Write kKeyGenScript
>> tos.WriteLine
>> tos.Flush
>>
>> tos.close
>> tos = Nil
>> Else
>> MsgBox "tempfile creation failed"
>> End If
>>
>> However, after executing the code, the temp file exists and there
>> are no errors with the f or tos assignments, but the file is empty.
>>
>> I've double checked the constant and it is properly defined and
>> marked as global.
>>
>> Any ideas?
>>
> Which platform?

OS X and Linux

> Console or GUI?

GUI

> In a Mac OS app, the end-of-line written by tos.WriteLine is
> different in console v. GUI builds. If you check the result using
> cat, nothing is written to stdout when the EOL terminator is
> EndOfLine.Mac.

The constant has Unix EOLs embedded. That's why I use tos.Write to
write the file out. I'd also tried setting teh tos.Delimiter to
EndOfLine.UNIX with the same result, even though it shouldn't matter.

> Otherwise, I ran this code and saw the expected result.

Hmmm, I just tried with a shorter constant ( 25 characters) and it
still failed.

BTW - I'm not cat'ing the file, but monitoring its size. The size
remains 0 bytes.

>
> Next, my standard nit-picking -- you might want to pass
> FolderItem.PathTypeShell to GetFolderItem.

I'd actually tried both ways and the folderitem call and
f.AppendToTextFile,

> And instead of
>
>> tos.Write kKeyGenScript
>> tos.WriteLine
>
> you can just do
>
> tos.WriteLine kKeyGenScript

They were remnants from tests to try and cause the expected result.
However, I haven't tried using WriteLine to actually write the
constant, but it trying that gives the same result.

Tim

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Can't write to text file?
Date: 02.08.09 20:58 (Sun, 2 Aug 2009 15:58:45 -0400)
From: Charles Yeomans

On Aug 2, 2009, at 1:22 PM, Tim Jones wrote:

> Hi Folks,
>
> I'm trying to write the contents of a string constant out to a
> temporary file. I'm using the following code in a method:
>
> Dim theShell As New Shell
> Dim theScript As String
> Dim f As FolderItem
> Dim tos As TextOutputStream
>
> theShell.Execute "mktemp /tmp/keyscript.XXXXXX"
> theScript = NthField(theShell.ReadAll, EndOfLine, 1) // just get
> the file and path
>
> f = GetFolderItem(theScript)
> If f.Exists And f.IsWriteable Then
> tos = f.AppendToTextFile // file exists from mktemp call above
>
> tos.Write kKeyGenScript
> tos.WriteLine
> tos.Flush
>
> tos.close
> tos = Nil
> Else
> MsgBox "tempfile creation failed"
> End If
>
> However, after executing the code, the temp file exists and there
> are no errors with the f or tos assignments, but the file is empty.
>
> I've double checked the constant and it is properly defined and
> marked as global.
>
> Any ideas?
>

Which platform? Console or GUI? In a Mac OS app, the end-of-line
written by tos.WriteLine is different in console v. GUI builds. If you
check the result using cat, nothing is written to stdout when the EOL
terminator is EndOfLine.Mac. Otherwise, I ran this code and saw the
expected result.

Next, my standard nit-picking -- you might want to pass
FolderItem.PathTypeShell to GetFolderItem. And instead of

> tos.Write kKeyGenScript
> tos.WriteLine

you can just do

tos.WriteLine kKeyGenScript

Charles Yeomans

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Can't write to text file?
Date: 02.08.09 20:51 (Sun, 2 Aug 2009 12:51:43 -0700)
From: Tim Jones
On Aug 2, 2009, at 12:26 PM, <email address removed> wrote:

>> Hi Folks,
>>
>> I'm trying to write the contents of a string constant out to a
>> temporary file. I'm using the following code in a method:
>>
>> Dim theShell As New Shell
>> Dim theScript As String
>> Dim f As FolderItem
>> Dim tos As TextOutputStream
>>
>> theShell.Execute "mktemp /tmp/keyscript.XXXXXX"
>> theScript = NthField(theShell.ReadAll, EndOfLine, 1) // just get
>> the file and path
>>
>> f = GetFolderItem(theScript)
>> If f.Exists And f.IsWriteable Then
>> tos = f.AppendToTextFile // file exists from mktemp call above
>>
>> tos.Write kKeyGenScript
>> tos.WriteLine
>> tos.Flush
>>
>> tos.close
>> tos = Nil
>> Else
>> MsgBox "tempfile creation failed"
>> End If
>>
>> However, after executing the code, the temp file exists and there are
>> no errors with the f or tos assignments, but the file is empty.
>>
>> I've double checked the constant and it is properly defined and
>> marked as global.
>>
>> Any ideas?
>>
>> Thanks,
>> Tim
>
> Is it possible that the code is moving faster than the mktemp
> command is
> completing, or does shell.execute pause things until the command
> completes?

The shell is in Mode 0, so the mktemp call completes before the code
continues.

As I said, the temp file is created, and the folderitem and
textoutputstring calls all report success. Checking the Len of
kKeyGenScript reports the proper size (23,741 characters).

Tim

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Can't write to text file?
Date: 02.08.09 20:27 (Sun, 02 Aug 2009 21:27:02 +0200)
From: Markus Winter
> tos.Write kKeyGenScript
> tos.WriteLine
> tos.Flush

I'm not clear on what you are doing here? Why not just the first line?

Markus


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Can't write to text file?
Date: 02.08.09 20:47 (Sun, 2 Aug 2009 12:47:09 -0700)
From: Tim Jones
On Aug 2, 2009, at 12:27 PM, Markus Winter wrote:

>> tos.Write kKeyGenScript
>> tos.WriteLine
>> tos.Flush
>
> I'm not clear on what you are doing here? Why not just the first line?

The other two were added as the first didn't seem to accomplish the
result I was looking for.

Tim

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Can't write to text file?
Date: 02.08.09 20:26 (Sun, 2 Aug 2009 12:26:22 -0700 (PDT))
From: fargo rpgportland.com
> Hi Folks,
>
> I'm trying to write the contents of a string constant out to a
> temporary file. I'm using the following code in a method:
>
> Dim theShell As New Shell
> Dim theScript As String
> Dim f As FolderItem
> Dim tos As TextOutputStream
>
> theShell.Execute "mktemp /tmp/keyscript.XXXXXX"
> theScript = NthField(theShell.ReadAll, EndOfLine, 1) // just get
> the file and path
>
> f = GetFolderItem(theScript)
> If f.Exists And f.IsWriteable Then
> tos = f.AppendToTextFile // file exists from mktemp call above
>
> tos.Write kKeyGenScript
> tos.WriteLine
> tos.Flush
>
> tos.close
> tos = Nil
> Else
> MsgBox "tempfile creation failed"
> End If
>
> However, after executing the code, the temp file exists and there are
> no errors with the f or tos assignments, but the file is empty.
>
> I've double checked the constant and it is properly defined and
> marked as global.
>
> Any ideas?
>
> Thanks,
> Tim

Is it possible that the code is moving faster than the mktemp command is
completing, or does shell.execute pause things until the command
completes?


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>