[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


Janitor application acceptance emails are being sent out. Please remember to check your spam box!


[Advertise on 4chan]


File: 1756747441976227.jpg (41 KB, 589x397)
41 KB
41 KB JPG
Any Powershell pros here? Why does StartsWith think the output begins with it?

$output_02193410 = "okds"
$output_02193410 = py script.py http://4chan.org/g
if ($output_02193410 -ceq "okds") { exit }
if ($output_02193410 -like "{'post': {'id':*") { Write-Host "like match" }
if (($output_02193410.StartsWith("{'post': {'id':"))) { Write-Host "startswith match" }
startswith match
Write-host "The output: ""$output_02193410""."
The output: "Request failed with error: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)). Retrying after 15 seconds... Received status code 404.".
>>
Why don't you just use Python
>>
>>107113659
Why do you care?
>>
>>107113667
I don't, that's why I didn't even bother figuring out what your nonsensical code does
>>
>>107113685
>cares about what the OP uses
>hurr durr i don't care

how are you this retarded? are you a chang, jeet or pinoy? drown yourself.
>>
>>107113700
>uhh you're le jeet!!1!
KYS
>>
>>107113700
>Projecting
>>
>>107113401
>)))
no real idea, but do you have too many parens there? then maybe it always writes
>>
>>107113731
>>107113712
50% chance you're a pinoy/chang acting like a triggered jeet and a 50% chance that you're a jeet. either way, we need to exterminate all three of you. average iq on the internet will increase.
>>
>>107113401
Jesus christ man.

Why do you name your output variable "output_02193410" and not just output?

What's with the first if statement? Just else the 2nd one and make it exit after that.

Why even assign a gibberish statement to it in the first place in your execution? You can just check if it's null/empty string.

Jesus FUCKING christ I tried to decipher what you're even trying to do within the 2nd and 3rd conditionals but you are a total shiteating jeet and I'm not going to spoonfeed you anything. Just accept your defeat and let a white man take your job back, brownoid scammer.
>>
>>107114118
the OP is troubleshooting why startswith is garbage. the fact that you couldn't tell means you're a self-hating street shitter projecting yourself onto others to look white. though you could be a falseflagging pinoy/chang as another anon pointed out as changs/pinoys worship whites more than jeets do.
>>
>>107113659
Your average corpoputer does not support python natively.
It does support powershell though.
As a corposlave, I don't want to deal with IT's antics. So I'll use the language that'll work without having to ask anything from them.
Also, powershell integrates well with the rest of Microsoft ecosystem (Office, ActiveDirectory, Exchange, ...)
>>
>>107114197
Just go follow the powershell course on codecademy and stop asking retarded questions because you don't understand syntax fundamentals
>>
>>107113401
Why does PowerShell always look like the worst elements of Perl and Shell script mixed together?
>>
>>107113401
your retardedly named variable is probably an array that contains multiple strings, and one of the string contains ANSI escape sequences that clear the line. you don't need to use write-host, you can just eval the variable in the shell
PS C:\Users\Me> $output_02193410 = @("{'post': {'id':'123'}}"; "`x1b[2K`rRequest failed with error: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)). Retrying after 15 seconds... Received status code 404.")

PS C:\Users\Me> Write-Host "The output: ""$output_02193410""."
Request failed with error: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)). Retrying after 15 seconds... Received status code 404.".

PS C:\Users\Me> $output_02193410
{'post': {'id':'123'}}
Request failed with error: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)). Retrying after 15 seconds... Received status code 404.

PS C:\Users\Me> $output_02193410.StartsWith("{'post': {'id':")
True
False

TL;DR: why the fuck are you manipulating the output of a python script in powershell?
>>
>>107114329
The verbosity is a feature, not a bug. You will begin to appreciate it once you've had to dig up a 5 year old script and realized you can actually understand what each line does because it's not jam packed with arcane 2-6 letter unix programs that each have their own unique semantics.
>>
>>107114329
they modeled it after system calls, then thought that was too hard, then modeled it after vb.net, then needed to be different. The implementation of the bash alias are a fucking trainwreck if you have looked into them.

>>107114338
he didn't even notice that Write-Host "like match" didn't output. Clearly just cobbling chatGPT and SO. I'm quite confused why you think he would understand what types are.
>>
>>107114338
I'm not manipulating it. I wrote the output to the console and I don't see "{'post': {'id':'123'}}" in it. I'm wondering why StartsWith says it's there when it's not.
>>
>>107114388
why are you pinoys/chinks/jeets so retarded lmao
>>
>>107113401
Can any Powershell pro here explain to me why this bitch takes 500ms+ to start, even without a profile being loaded? thx
>>
>>107113401
Bro, this is a mess. RTFM and start over.
>>107115083
.net
>>
>>107115185
you're a fucking retard
>>
>>107115196
You must be OP.
>>
>>107115208
>can't read 5 short lines written by humans
>schizo (types incoherently and makes retarded accusations)
>writes shit code no one can read
>clearly mentally retarded

you're a pinoy, chink or a jeet.
>>
>>107113401
PowerShell has uglier syntax than Perl.
>>
>>107115223
OP is clearly an H-1B poo poo man. OP, my advice to you is give up and let AI do it for you.
>>
>>107113401
>Windows can't be used without a terminal
I can't believe Linux and Windows swapped places.
>>
>>107115297
>can't be used without a terminal
Elaborate.
>>
>>107115336
Context?
>>
>>107115297
Windows simply can't be used. Terminal or not.
>>
>>107115351
This post >>107115297 is saying Windows can't be used without a terminal. I'm asking what they mean.
>>
>>107115367
Source?
>>
>>107115372
Source of what? The post? I linked it.
>>
>>107115381
I accept your concession.
>>
>>107115420
I'm not even sure what you're talking about Anon. And I don't even know how to clarify the question to be any more direct or clear.
What were you talking about?
>>
>>107114329
>>107115232
lol. Yeah, Powershell is your typical MS mishmash of ideas and functionality. Once it clicks though, it’s actually an excellent data processing and manipulation language.
>>
>>107115495
it's so good that it returns false positives as the OP demonstrated
>>
>>107115336
Doing basic shit requires a terminal. Even installing the OS offline can't be done without fucking with the cmd.
>>
>>107115520
Never encountered this problem myself so I can't say I agree or know what you mean.
Windows has had graphical installers for a long time. And I do basic stuff on it all the time.
I'm curious what people are doing in the terminal. I practically live in mine but that's because I use vim for development. Hard to imagine users are using the terminal for anything.
>>
>>107115513
There are unlimited examples of erroneous code written in every language. Silly to jump to conclusions after a random one imo.
>>
>>107115513
Nah, OP just has no idea how to write idiomatic Powershell, and can’t even articulate what he’s actually trying to accomplish. He’s probably a jeet considering he’s trying to get us to do his work for him.
>>
File: IMG_6008.jpg (24 KB, 596x335)
24 KB
24 KB JPG
>>107113667
>>107113700
>>107113401
>>107114378
>>
>>107115561
how is it random? it should've never returned positive because it's nowhere in the output.

>>107115581
>SAAAAAAAAAR U DONT LIKE MICROSHIT?
>YOU BLOODY BENCHOD BASTARD MICROSOFT IS BILLIONAIRE SUCESSFULL COMPANY YOU UNDERSTAND
>U ARE JEET!!!!!!!!!!!!!! SAAAAAAAAAAR

ok
>>
>>107116005
>how is a random example in a random thread random?
You might be right.
>>
>>107116010
>output doesn't start with {'post': {'id':"
>powershell's inbuilt tool thinks it does
>"CHING CHONGGGGGGGG TOO RANDOM"

what the fuck are you on, chang? opium?
>>
>>107116092
I'm guessing you're just joking around.
Do you want a serious answer?
>>
>>107116103


if you had an answer you would've given it, chang from reddit.
>>
>>107116151
Obviously not. I don't want to write an answer that you don't want to read.
I think you want interaction, not information. I don't have to talk technical to talk to you, you know? You have to let me know which one you want.
>>
>>107113401
idk mang, I can't even tell the script from the output
also probably your output is garbage and >>107114338 is right
>>
>>107116222
>>107116163
>samefags
>ignores the OP

chang moment
>>
>>107116259
I'm >>107116163
None of the posters linked in >>107116222 are me.

I have a serious response for your original inquiry prepared for you upon request, should you want it, just let me know.

Regards,
Anonymous.
>>
>>107113401
powershell is jeetware, that's why.

-like was copy pasted from gnu, so it obviously works.

jeets made startswith/endswith, hence why it's buggy 99% of the time.
>>
>>107116259
OP asks people to debug his shit for him and provides 0 info about what the python script produces
respectfully kys
>>
>>107116304
the OP told you what's in the output, fuck off

stop defending the jeetware known as powershell
>>
>>107116310
>the OP told you what's in the output
not the output of the python script you dumb gorilla nigger, if OP bothered to format his post properly there would have been 0 confusion
>>
>>107116259
retard you have been given all the information you need
write-host will process ansi escape codes so you can't use it as a way to see what an array of strings contains
methods applied to arrays are applied to each individual element
if $var contains 100 strings and one of them starts with "fuckyou" then
if ($var.StartsWith('fuckyou'))
will return true

you will never be a proficient programmer. you should heed my advice and give up now and pick up a different trade like chopping wood or mining coal
>>
>>107116310
There’s OP again lol
>>
>>107113401
convert the JSON output to PSObject you dumb fuck
>>
>>107116329
where
do
you
see
"fuckyou"
in
the
output
,
chang
?
>>
>>107113401
it's probably UTF-8 with a BOM or your program output text as UCS-2 or some other bullshit, because M$ is fucking retarded.

in $PROFILE, I have
$PSDefaultParameters['Out-File:Encoding'] = 'UTF8NoBOM'
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

which fixes most the bigger issues with powershit when it comes to console output and saving files correctly.
>>
>>107116383
nvm. I reread it, you're just tarded. your program is failing.
>>
foreach ($entry in $output_02193410) {
$entry
}


>Request failed with error: SOCKSHTTPSConnectionPool(host='kemono.cr', port=443): Max retries exceeded with url: /api/v1/fanbox/user/4563795/post/10825252 (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x0000019A6CDF4980>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it')). Retrying after 15 seconds...
>Received status code 404.

StartsWith said this starts with "{'post': {'id':". I don't see what I'm doing wrong.
>>
https://github.com/PowerShell/PowerShell/issues?q=startswith

jeetware
>>
>>107115297
this has been the way it always was though. there are a lot of legitimate things you can do in Windows that requires significantly more technical fuckery and know-how than Linux and it has been this way since well before 7. I still have to write short C++ programs to probe specific, poorly exposed APIs to do basic shit. You can find a bunch of FOSS C# PInvoke ore random 2005 C++ projects that do a bunch of shit M$ still doesn't expose well to users and admins.
>>
>>107116406
>I don't see what I'm doing wrong
Trying to act fancy with JSON. Why are you not converting it to an object?
>>
>>107116406
run
$output_123456789 = py script.py http://4chan.org/g
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($output_123456789))

and post the result
>>
>>107116462
its not even json, it's using single quotes. i have no idea what fucked up eldritch chatgpt abominations hide in his python script
>>
>>107116490
>i-its le chatgpt
Kys microshill jeet
>>
>>107116475
IlJlcXVlc3QgZmFpbGVkIHdpdGggZXJyb3I6ICgnQ29ubmVjdGlvbiBhYm9ydGVkLicsIENvbm5lY3Rpb25SZXNldEVycm9yKDEwMDU0LCAnQW4gZXhpc3RpbmcgY29ubmVjdGlvbiB3YXMgZm9yY2libHkgY2xvc2VkIGJ5IHRoZSByZW1vdGUgaG9zdCcsIE5vbmUsIDEwMDU0LCBOb25lKSkuIFJldHJ5aW5nIGFmdGVyIDE1IHNlY29uZHMuLi4gUmVjZWl2ZWQgc3RhdHVzIGNvZGUgNDA0LiI=

>>107116462
$output_02193410 = $output_02193410 | ConvertFrom-Json
| ~~~~~~~~~~~~~~~~
| Conversion from JSON failed with error: Unexpected character encountered while parsing value: R. Path '',
| line 0, position 0.
-
startswith match
>>
I don't get it but look
https://tio.run/##HcqxCoAgEADQva84DgeF6g/a2xucJSwF09ADjejbr@jN70zV5uJsCMyiwQSIPWLnN5BStHEhk6loT06iiRc5H3dUSsENOnuyw5wKAZa/1a/BYWh1CA/zCw
seems like any array with more than one element is a positive match to startswith
>>
>>107115066
why are racists so unoriginal, boring and fail to prove their point every time?
>>
>>107116588
If you run stting functions on an array it will return an array of results.
For example
$x = "a", "b", "c"
$x.ToUpper()
Will return an array of uppercase letters

An array with multiple elements is considered truthy, so the if check passes.
>>
>>107117831
yeah, that's about as dumb a behaviour as I thought it was gonna be
>>
>>107117831
that makes no sense. i hate jeets so much.
>>
here you go retard gpt'd it for you

you get:

startswith match
The output: "Request failed with error: ('Connection aborted.', ConnectionResetError(10054, ... 404)".
So StartsWith fires, even though the output looks like it clearly doesn’t start with that string.
What’s really happening
The key is this line:
$output_02193410 = py script.py http://4chan.org/g
PowerShell doesn’t automatically capture stdout as a string from an external command the way Bash does. Instead:
$output_02193410 receives an array of output lines (a [string[]]).

If py script.py printed multiple lines, $output_02193410 now holds multiple entries.

When you call .StartsWith() on an array, PowerShell unwraps the array to the first element silently — or coerces it in strange ways that can trigger .StartsWith() on one of the array’s items.

So if your script prints multiple lines, and one of the first lines does start with "{'post': {'id':", then .StartsWith() returns True, even if the final line (what you see in Write-Host) looks totally different.
To confirm what’s happening
Add these debugging lines:
$output_02193410.GetType().FullName
$output_02193410 | ForEach-Object { "[LINE] $_" }
You’ll see:

System.Object[]
[LINE] {'post': {'id': 12345}}
[LINE] Request failed with error: ...
So the .StartsWith() matched the first element.
How to fix it

If you only care about the full text output as one string, force PowerShell to join it:

$output_02193410 = py script.py http://4chan.org/g | Out-String


Now it’s a single [string], and your StartsWith will behave as expected.

Or, if you want to check the first line only, be explicit:

if ($output_02193410[0].StartsWith("{'post': {'id':"))) {
Write-Host "startswith match"
}
>>
>>107118987
That's wrong, anon already figured it out here >>107117831
>>
why ps.exe starts over 1 sec?
why not just include python in windows?
>>
>>107119479
>python
micropython
>>
why small basic so useless shit?
>>
https://github.com/russhughes/micropython_sdl2
windows port pls
>>
so cring



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.