Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
RokosCockatrice
Feb 19, 2004

I have a lot of points to make and I will make them later.
Stack Overflow recommended to get a better answer than "object", I should try `Object.prototype.toString.call(thing)`. Reading stack overflow was probably the big mistake here.

Adbot
ADBOT LOVES YOU

mystes
May 31, 2006

What are you trying to do?

mystes fucked around with this message at 14:54 on Jun 2, 2023

RokosCockatrice
Feb 19, 2004

I have a lot of points to make and I will make them later.
I was trying to figure out what the type of this unknown return value is so I can use it in my code.

mystes
May 31, 2006

if you're trying to print it for debugging wouldn't you want stringify not parse?

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
it looks like it's an array, op

polyester concept
Mar 29, 2017

Jabor posted:

it looks like it's an array, op

polyester concept
Mar 29, 2017

mystes posted:

if you're trying to print it for debugging wouldn't you want stringify not parse?

yeah you want JSON.stringify(thing)

assuming thing is an array, thing.prototype.toString will just output every item as a comma separated string

12 rats tied together
Sep 7, 2006

expect is good, don't understand why you would be using it in anger

12 rats tied together fucked around with this message at 17:37 on Jun 2, 2023

FlapYoJacks
Feb 12, 2009
Why wouldnít you use python and Paramiko for ssh access? Then smash things into the shell?

12 rats tied together
Sep 7, 2006

expect is purpose built for this sort of thing so the code ends up being smaller and you write less of it which means there's less chance you screw up your parser and run a bunch of poo poo in the wrong context

it's also like decades old so the documentation is good and you can just learn it once and never have to update your understanding. anyway most of the time i write expect i use pexpect

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

distortion park posted:

How much data is there? Do you have an intern handy?

It's not a one-off thing, we want to build a cronjob that goes and grabs the up-to-date data as often as possible

12 rats tied together posted:

expect is purpose built for this sort of thing so the code ends up being smaller and you write less of it which means there's less chance you screw up your parser and run a bunch of poo poo in the wrong context

it's also like decades old so the documentation is good and you can just learn it once and never have to update your understanding. anyway most of the time i write expect i use pexpect

Thanks, I hadn't found pexpect yet and it might be helpful

The issue I'm currently having is that I'm not sure if the ASCII GUI I get from the mainframe is even supposed to work with expect. Like I can log through the SSH via expect just fine, but after that I need to press enter a couple of times to reach the right menu, and having "send '\r'" (with sleeps and --slow) in my script does nothing, at least nothing that shows up in the asciinema recording (it's not an issue with asciinema because it works when doing it manually w/o expect).

sb hermit
Dec 13, 2016





NihilCredo posted:

terrible programmer stories: we need to get some data off an ancient terminal ui (think curses) for a mainframe that is only accessible via SSH, because getting direct database access is apparently politically impossible, and the web api has only half the data we need

so after writing a straightforward c# backend service to query the web api, I'm now loving around with a docker that starts asciinema and trying to write a tcl script for expect(1) to navigate the 80s menus automatically

(I was hoping to do it in python but using asciinema as a library craps out with just error code 1)

has anybody used expect(1) in anger before? my beard is not that grey

I think I used expect(1) to automate device testing over serial and itís real fun to use but that must have been like 20 years ago or so

fins
May 31, 2011

Floss Finder

NihilCredo posted:

It's not a one-off thing, we want to build a cronjob that goes and grabs the up-to-date data as often as possible

Thanks, I hadn't found pexpect yet and it might be helpful

The issue I'm currently having is that I'm not sure if the ASCII GUI I get from the mainframe is even supposed to work with expect. Like I can log through the SSH via expect just fine, but after that I need to press enter a couple of times to reach the right menu, and having "send '\r'" (with sleeps and --slow) in my script does nothing, at least nothing that shows up in the asciinema recording (it's not an issue with asciinema because it works when doing it manually w/o expect).

maybe force a tty with ssh -t host

or '\r\n' instead of '\r'

12 rats tied together
Sep 7, 2006

in normal expect iirc you expect the prompt you're looking for and include expect_continue which turns it into a little poller by resetting the timeout and then expecting again

pexpect otoh kinda sucks because you expect with a timeout and it raises an exception that you have to catch, but you can catch it and retry

either way it's not too bad to implement "keep sending enter until you get a prompt, and then ...". you gotta find out what character enter is sending though.

Doom Mathematic
Sep 2, 2008

RokosCockatrice posted:

I was trying to figure out what the type of this unknown return value is so I can use it in my code.

Please post the actual inputs you typed and the console outputs you were given. The examples you gave were ambiguous to a point which makes it impossible for thing to be anything really.

For example, it's impossible for Object.prototype.toString.call(thing) to return "string". I'm guessing that what you meant is that it actually returned "[object String]", which means thing is definitely a string, and definitely not an array. Yet elsewhere you're calling thing.map with no problems and thing instanceof Array is returning true, which means thing is definitely an array and definitely not a string.

Poopernickel
Oct 28, 2005

electricity bad
Fun Shoe

NihilCredo posted:

terrible programmer stories: we need to get some data off an ancient terminal ui (think curses) for a mainframe that is only accessible via SSH, because getting direct database access is apparently politically impossible, and the web api has only half the data we need

so after writing a straightforward c# backend service to query the web api, I'm now loving around with a docker that starts asciinema and trying to write a tcl script for expect(1) to navigate the 80s menus automatically

(I was hoping to do it in python but using asciinema as a library craps out with just error code 1)

has anybody used expect(1) in anger before? my beard is not that grey

I've used expect before, and also pexpect (expect, but Python). It's reasonably needs-suiting. Works best if you're an old though.

Why do you need asciinema? Can you launch ssh in a subprocess and just capture the stdout?

Poopernickel fucked around with this message at 23:51 on Jun 2, 2023

Corla Plankun
May 8, 2007

improve the lives of everyone

NihilCredo posted:

terrible programmer stories: we need to get some data off an ancient terminal ui (think curses) for a mainframe that is only accessible via SSH, because getting direct database access is apparently politically impossible, and the web api has only half the data we need

so after writing a straightforward c# backend service to query the web api, I'm now loving around with a docker that starts asciinema and trying to write a tcl script for expect(1) to navigate the 80s menus automatically

(I was hoping to do it in python but using asciinema as a library craps out with just error code 1)

has anybody used expect(1) in anger before? my beard is not that grey

how much data? I've banged out something like this (extracting inventory data from an as400 via an insanely jank terminal emulator) with autohotkey navigating, copying, and pasting data into a spreadsheet but obviously that would take ages if it was more than ~thousands of records.

MrQueasy
Nov 15, 2005

Probiot-ICK

tef posted:

drove my coworker mad that i was using vim over ssh on a machine 5000mi away, couldn't understand how i dealt with the lag

vi was designed to make you feel productive despite lag

mystes
May 31, 2006

Nothing.makes you productive with lag like an editor where you constantly belatedly realize you were in the wrong mode and not actually entering the text you thought you were

Soricidus
Oct 21, 2010
freedom-hating statist shill
this is why you use something like emacsí tramp. run the editor locally, only notice latency when actually doing io

mystes
May 31, 2006

Vscode has something like that too

redleader
Aug 18, 2005

Engage according to operational parameters
you wouldn't have that problem if you didn't use a modal editor

quiggy
Aug 7, 2010

[in Russian] Oof.


actually vi is good

CPColin
Sep 9, 2003

Big ol' smile.
yeah, final fantasy vi

ikanreed
Sep 25, 2009

I honestly I have no idea who cannibal[SIC] is and I do not know why I should know.

syq dude, just syq!
Can your text editor suplex a train?

mystes
May 31, 2006

ikanreed posted:

Can your text editor suplex a train?
My terminal can multiplex the sl command does that count

InternetOfTwinks
Apr 2, 2011

Coming out of my cage and I've been doing just bad
Modal editing is really not that complicated, I had the basics pretty much down in like, a week or two

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

InternetOfTwinks posted:

Modal editing is really not that complicated, I had the basics pretty much down in like, a week or two
I'm not sure that's the ringing endorsement you might think it is

mystes
May 31, 2006

Modal editing is great. You just have to stick with it for long enough for the Stockholm syndrome to kick in

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
i type seconds ahead of vim updating pretty regularly and itís completely fine 99% of the time but sometimes you discover that the entire file is now lowercase and have to back up a few steps

FlapYoJacks
Feb 12, 2009
After a few months of using it: MISRA is cool and good. except for the rule that only allows one return in a method. It leads to a lot of nested if statements.

mystes
May 31, 2006

FlapYoJacks posted:

After a few months of using it: MISRA is cool and good. except for the rule that only allows one return in a method. It leads to a lot of nested if statements.
I hear that's hard to treat good luck

qsvui
Aug 23, 2003
some crazy thing
how is anyone typing ahead of their editor in tyool 2023? just ask your work for a better computer

qsvui
Aug 23, 2003
some crazy thing

mystes posted:

I hear that's hard to treat good luck

sounds misrable

FlapYoJacks
Feb 12, 2009

qsvui posted:

how is anyone typing ahead of their editor in tyool 2023? just ask your work for a better computer

Look it, my brother word processor was fine in 1989 and itís fine now!!!!

mystes
May 31, 2006

qsvui posted:

how is anyone typing ahead of their editor in tyool 2023? just ask your work for a better computer
the original discussion was about over laggy connections and for some reason someone suggested that vi would be a good idea in this situation for reasons that are not clear to me since whenever I've tried to use vi over a laggy connection I've wanted to shoot myself

FlapYoJacks
Feb 12, 2009
Nano first, then VIM.

quiggy
Aug 7, 2010

[in Russian] Oof.


i mean i actually use Rider with vim keybinds but w/e

Antigravitas
Dec 8, 2019

Die Rettung fuer die Landwirte:
Oh no, you have jetbrain

Adbot
ADBOT LOVES YOU

FlapYoJacks
Feb 12, 2009
Jetbrain IDEs are the best IDEs.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply