OpenEdge 10.2A - INPUT THROUGH set does not work after Windows Update 1703 on Windows 10 - set

We were using below code to get the name of the computer.
def new shared var cHost as char format "x(40)" no-undo.
INPUT THROUGH hostname NO-ECHO.
SET cHost.
INPUT CLOSE.
DISPLAY chost.
After we have updated our computers (Windows 10 - 1703), it no longer works. It seems SET cHost is the part where it fails. I have tried IMPORT UNFORMATTED cHost but it does not work.
PS: I can get computer name using OS-GETENV("COMPUTERNAME") but I have to do it using INPUT THROUGH statement.
Edit: It seems that it is not only a problem with 10.2A but a more general one. Also it is not just related to hostname but all console applications and ms-dos commands. Now I will try to replace INPUT THROUGH statement with another Progress command if there is any, or try to communicate with existing console applications with some other method.

The first thing I would do is to verify that the 'hostname' command is still working properly from a command window.
Assuming that it is I would code your snippet something like this:
INPUT THROUGH VALUE( "hostname" ).
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
DISPLAY cHOST format "x(60)".
Which might reveal a more useful error message than "it no longer works".
Since COMPUTERNAME meets your needs but you must use INPUT THROUGH for some very mysterious reason you might also try:
INPUT THROUGH VALUE( "echo %COMPUTERNAME%" ).
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
DISPLAY cHOST format "x(60)".

It seems the problem may not be limited to Openedge version 10. I am running a windows 10 winver 1703 device for development, using Progress/Openedge 8.3 and I am no longer able to execute this.
def var a as char format "x(70)".
input through "echo %cd%" no-echo.
import unformatted a.
input close.
message a. pause.
This runs on a windows server 2012 R2, using progress/openedge 8.3.
Where is no longer works, it just exits from within the program when it hits the import command.

Since it seems as a bug, until someone comes up with a better solution, this is how I will change my codes:
DEF VAR cHost AS CHAR FORMAT "x(40)" NO-UNDO.
OS-CREATE-DIR VALUE("c:\temp").
OS-COMMAND SILENT VALUE("hostname >c:\temp\hostname.txt").
INPUT FROM VALUE("c:\temp\hostname.txt").
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
MESSAGE cHost.
This code can be used for other ms-dos commands and console applications as well.
DEF VAR cHost AS CHAR FORMAT "x(40)" NO-UNDO.
OS-CREATE-DIR VALUE("c:\temp").
OS-COMMAND SILENT VALUE("ECHO %cd% >c:\temp\result.txt").
INPUT FROM VALUE("c:\temp\result.txt").
IMPORT UNFORMATTED cHost.
INPUT CLOSE.
MESSAGE cHost.
Thanks for your help.

Related

Xcode Breakpoint and LLDB - How do I open a file (e.g. in Preview) from a given fileURL stored in a variable?

I have a variable in Swift code that runs in iOS simulator and contains an existing fileURL. I want to have the file opened in macOS (not the iOS Simulator) when I hit a breakpoint.
I added an action "Shell Command" to the breakpoint to open the file. The file exists because if I copy-paste the file's path to Terminal, it opens in Preview.
However, the Xcode console says the contrary:
The file /"/Users/tomkraina/Library/Developer/CoreSimulator/Devices/FBA16E00-9450-40E8-9650-1489A67E344C/data/Containers/Data/Application/BB97DB72-FF2A-4087-BD42-2934C63D3323/tmp/7E2303B8-0629-475A-862A-2550351FB448/OutlineExport.pdf" does not exist.
First Question: How do I tell Xcode to open a file with provided fileURL in a variable on breakpoint?
Next thing I tried was to open the file using LLDB, but I cannot find out how to evaluate a command parameter in LLDB, because backticks is only for scalars:
(lldb) shell open `temporaryFile.fileURL.path`
The file /105553157711856 does not exist.
Second Question: How to I evaluate argument parameter to get a string in LLDB?
I don't have a good answer for the first question. It would be interesting to check whether the path that is in the Xcode error message is correct - maybe it's getting it from the value incorrectly. If you copy the path from the error message, go to Terminal and try to open it, does that work? Anyway, this sounds to me like a bug in Xcode. It got some kind of path out of your variable and tried to open it, which should have worked. If you want to follow up, it's probably best to file a bug report with the Apple Feedback.
For the second question, you have to know a little about how variables work in lldb. Some variables have obvious values, for instance, in C a pointer has the pointer value, an integer the integer value, etc. Other variables (any kind of Struct being the obvious example) are actually containers of other values and don't really have a "value" themselves.
lldb can show you what a swift string really is using the --raw option:
(lldb) v --raw str1
(Swift.String) str1 = {
_guts = {
_object = {
_countAndFlagsBits = {
_value = -3458764513820540912
}
_object = 0x8000000100003f50 (0x0000000100003f50) strings`symbol stub for: Swift.print(_: Any..., separator: Swift.String, terminator: Swift.String) -> () + 4
}
}
}
That's probably really interesting to people working on the Swift Standard Library and has the virtue of being the truth. But for most purposes, it's not a terribly useful representation.
lldb handles that problem by adding a notion of "Summary Formatters" that generate a string representation for objects based on their type. There's one for "Swift.string" that digs around in the object, finds where the actual string is, and returns that text. If you don't pass --raw and there's a summary formatter, then lldb will show you the summary:
(lldb) v str1
(String) str1 = "some string here"
That is also the value that you want to try and open.
The backtick syntax in lldb gets the value of the entity, not its summary, which is why that didn't work for a swift string. However, you can fetch and act on the summaries for local variables using lldb's Python interpreter and the SB API. So for instance:
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> var = lldb.frame.FindVariable("str1")
>>> var.GetSummary()
'"some string here"'
So then if that was a file path you wanted to open, you can use Python to do that, like:
>>> os.system("open {0}".format(var.GetSummary()))
The file /private/tmp/some string here does not exist.
256
except of course your var has to hold the path to a real file...
If you want to learn more about the lldb Python API's the API docs are here:
https://lldb.llvm.org/python_api.html
and a general tutorial for using Python in lldb is here:
https://lldb.llvm.org/use/python-reference.html
And more information on variable formatting is here:
https://lldb.llvm.org/use/variable.html

How I can load a font file with PIL.ImageFont.truetype in replit

I'm trying to make this welcome card thingy in discord.py and I'm running my bot on replit.com as of now.
font = ImageFont.truetype("arial.ttf", 28)
I got some examples and it worked great as long as I'm running it on my PC but wen I get to replit.com it gives the error saying
Command raised an exception: OSError: cannot open resource
How should I go about correcting this?
I don't know discord or replit but presume the issue is that you can't upload your binary font file.
If so, you have a couple of options:
find your desired font online somewhere and use requests.get(URL) to grab it in your code on replit, or
make a base64 variable in your code and decode it
The first option is covered here.
Let's look at the second. Say your font is called /Fonts/funky.ttf on your PC. Now you want that in base64 which you can do with a commandline tool on your local PC:
base64 < /Fonts/funky.txt
That will make a long string of characters. Copy it, and in your Python code add a string called font64 and set it equal to the pasted string, i.e.
font64 = 'PASTED STRING'
Now in your code you can convert the string back from base64 to binary, then wrap it in a BytesIO to make it look like a file and load it:
import base64
import io
from PIL import ImageFont
font64 = 'PASTED STRING'
# decode from base64 to binary
binary = base64.b64decode(font64)
# wrap in BytesIO to make file-like object
FileLike = io.BytesIO(binary)
# load font
font = ImageFont.truetype(FileLike, 28)

Xojo MacOs Vs. Windows? EndOFLine issue

So I created a program on Xojo(MacOS) that parses paragraphs using EndofLine. However, when I run it on a Windows operating system it doesn't parse it at all. Does Window operating systems recognize EndofLine or Chr(10)+Chr(13) in Xojo?
Xojo's EndOfLine constant is indeed different depending on the platform you use it for.
You have two choices of dealing with this:
Explicitly use a platform specific constant:
EndOfLine.Windows gives CR+LF
EndOfLine.Unix gives LF
The better way, especially if you import data from outside the program, e.g. when reading from a file or from a network socket, is to normalize the line delimiters for your internal use, like this:
normalizedString = ReplaceLineEndings (importedString, EndOfLine)
Now, you can use EndOfLine with normalizedString, e.g. to split it into single lines:
dim lines() as String = normalizedString.Split (EndOfLine)
When you write this string back, you'll automatically have it in the system's format already.
However, when you export your text to a system where you know it expects them in a certain format, convert them back to that format like this:
// E.g, if you export them for a Mac:
outputString = ReplaceLineEndings (internalString, EndOfLine.Unix)
EndOfLine is always platform dependent, so in case of Windows, its value is chr(13)+chr(10), while on macOS it's chr(10). You can reach these platform-specific values directly by using EndOfLine.Windows and EndOfLine.OSX.
To normalise the line endings in a string, you can use the ReplaceLineEndings() function.

Darwin Streaming Server install problems os x

My problem is the same as the one mentioned in this answer. I've been trying to understand the code and this is what I learned:
It is failing in the file parse_xml.cgi, tries to get messages (return $message{$name}) from a file named messages (located in the html_en directory).
The $messages value comes from the method GetMessageHash in file adminprotocol-lib.pl:
sub GetMessageHash
{
return $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"}
}
The $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} is set in the file streamingadminserver.pl:
$ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} = $messages{"en"}
I dont know anything about Perl so I have no idea of what the problem can be, for what I saw $messages{"en"} has the correct value (if I do print($messages{"en"}{'SunStr'} I get the value "Sun")).
However, if I try to do print($ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"}{'SunStr'} I get nothing. Seems like $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} is not set
I tried this simple example and it worked fine:
$ENV{"HELLO"} = "hello";
print($ENV{"HELLO"});
and it works fine, prints "hello".
Any idea of what the problem can be?
Looks like $messages{"en"} is a HashRef: A pointer to some memory address holding a key-value-store. You could even print the associated memory address:
perl -le 'my $hashref = {}; print $hashref;'
HASH(0x1548e78)
0x1548e78 is the address, but it's only valid within the same running process. Re-run the sample command and you'll get different addresses each time.
HASH(0x1548e78) is also just a human-readable representation of the real stored value. Setting $hashref2="HASH(0x1548e78)"; won't create a real reference, just a copy of the human-readable string.
You could easily proof this theory using print $ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} in both script.
Data::Dumper is typically used to show the contents of the referenced hash (memory location):
use Data::Dumper;
print Dumper($messages{"en"});
# or
print Dumper($ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"});
This will also show if the pointer/reference could be dereferenced in both scripts.
The solution for your problem is probably passing the value instead of the HashRef:
$ENV{"QTSSADMINSERVER_EN_SUN"} = $messages{"en"}->{SunStr};
Best Practice is using a -> between both keys. The " or ' quotes for the key also optional if the key is a plain word.
But passing everything through environment variables feels wrong. They might not be able to hold references on OSX (I don't know). You might want to extract the string storage to a include file and load it via require.
See http://www.perlmaven.com/ or http://learn.perl.org for more about Perl.
fix code:
$$ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"} = $messages{"en"};
sub GetMessageHash
{
return $$ENV{"QTSSADMINSERVER_EN_MESSAGEHASH"};
}
ref:
https://github.com/guangbin79/dss6.0.3-linux-patch

VBScript and presenting an input box

I am writing a script to capture the login time. In the final production, there would be no input from any user. However I am testing it and I wanted to know how I add extra code to determine that
If its in 'debug' mode AND
The user that is logging in is me (lets say my username is joe.smith on the domain called EXAMPLE)
then present an input box to allow me to type the date, time for logging in.
All other users would never see this and it would capture today with the system time.
I would also like to hide the code so if the script is opened by the wrong person, they wouldnt be able to make heads or tails of whats going on.
You can use a command line parameter as Matt says to set the script into debug mode, eg
dim isdebug: isdebug = WScript.Arguments.Named.Exists("debug")
WScript.Echo("in debug mode: " & isdebug)
Which you can invoke with
wscript debugscript.vbs /debug
To get the current user name, you can use either the WMI Service or the WScript.Network object.
Once you have the username, you can conditionally throw up an InputBox and collect the value returned:
dim date_: date_ = Now()
if isdebug and username = "me" then
dim value: value = CDate(InputBox("enter the date and time (dd/mm/yyyy hh:mm:ss)", "please", Now()))
' validate the input here
date_ = CDate(value)
end if
And finally, to obfuscate your code you could use the Scripting.Encoder although it looks like this doesn't seem to be supported on Vista or Windows 7. There does seem to be a few hits on googling the phrase obfuscating vbscript, anyway.
Most of this sounds like it can be resolved by the logic of the script.
Have a command line parameter (debug is an appropriate name) and then have some if logic in the code to do as you wish (present the input box).
For the code obfuscation, I don't know how this could be done in vbscript. Windows scripting host works with JavaScript as well though and there are plenty of tools on the web for making JS harder to read. Maybe you want to look a using JS...
HTH,
Matt
I think you can check the property App.LogMode to see if you are in 'debug' mode or not. If it is 0 then you are running debug mode and if it is 1 you are not.

Resources