relational database – Is there a normal form for exactly identical tables?

Consider this design in a relational database:

There are two tables A, B, both having two columns X, Y. The constraints are:

  1. X in both tables are the primary keys. (The values are unique in each table.)
  2. The data in both tables must be exactly identical. (Each insert, delete, update request must be applied to the two tables together.)

It is obviously not an ideal design. But does it not conform to some normal forms? Which normal form and why?

Does the same hold if there is another column in both tables but not identical? Or some rows are removed in one table?

Kafka Broker Runs locally via docker compose but fails in kubernetes with near identical config

Kafka broker runs beautifully when running locally via docker-compose.

version: "3"
services:
  zookeeper:
    image: 'bitnami/zookeeper:latest'
    ports:
      - '2181:2181'
    environment:
      - ALLOW_ANONYMOUS_LOGIN=yes
  kafka:
    image: 'bitnami/kafka:latest'
    ports:
      - '9092:9092'
    environment:
      - KAFKA_BROKER_ID=1
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
    depends_on:
      - zookeeper

When running via kubernetes though

apiVersion: v1
kind: Service
metadata:
  name: zevrant-kafka-zookeeper-service
spec:
  ports:
    - port: 443
      targetPort: 2181
  selector:
    app: zevrant-kafka-zookeeper-service
---
apiVersion: v1
kind: Service
metadata:
  name: zevrant-kafka-service
spec:
  type: NodePort
  ports:Connection to node -1 (/<IP_ADDRESS>:30129) could not be established. Broker may not be available.
    - port: 443
      targetPort: 9092
      nodePort: 30129
  selector:
    app: zevrant-kafka-service
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: zevrant-kafka-zookeeper-service-deployment
  labels:
    app: zevrant-kafka-zookeeper-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zevrant-kafka-zookeeper-service
  template:
    metadata:
      labels:
        app: zevrant-kafka-zookeeper-service
    spec:
      volumes:
        - name: zookeeper-data
          nfs:
            server: <IP_ADDRESS>
            path: /zookeeper
      imagePullSecrets:
        - name: regcred
      nodeSelector:
        architecture: amd64
      containers:
        - name: zevrant-kafka-zookeeper-service
          image: bitnami/zookeeper:3.7.0
          env:
            - name: ALLOW_ANONYMOUS_LOGIN
              value: "yes"
          ports:
            - containerPort: 2181
          volumeMounts:
            - name: zookeeper-data
              mountPath: /bitnami/zookeeper
        - name: zevrant-kafka-zookeper-ui-service
          image: elkozmon/zoonavigator:1.1.0
          ports:
            - containerPort: 9000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: zevrant-kafka-service-daemonset
  labels:
    app: zevrant-kafka-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zevrant-kafka-service
  template:
    metadata:
      labels:
        app: zevrant-kafka-service
    spec:
      volumes:
        - name: kafka-storage
          hostPath:
            path: /opt/kafka/dev/
      imagePullSecrets:
        - name: regcred
      nodeSelector:
        architecture: amd64
      containers:
        - name: zevrant-kafka-broker-service
          image: bitnami/kafka:2.8.0
          volumeMounts:
            - name: kafka-storage
              mountPath: /bitnami/kafka
          ports:
            - containerPort: 9092
          env:
            - name: ALLOW_PLAINTEXT_LISTENER
              value: "yes"
            - name: KAFKA_CFG_ZOOKEEPER_CONNECT
              value: "zevrant-kafka-zookeeper-service:443"
            - name: KAFKA_BROKER_ID
              value: "1"
            - name: KAFKA_CFG_LISTENERS
              value: "PLAINTEXT://0.0.0.0:9092"
            - name: KAFKA_CFG_ADVERTISED_LISTENERS
              value: "PLAINTEXT://<IP_ADDRESS>:30129"

The broker starts but repeatedly spams the error

INFO (Admin Manager on Broker 1): Error processing create topic request CreatableTopic(name='zevrant-video-stream', numPartitions=1, replicationFactor=1, assignments=(), configs=()) (kafka.server.ZkAdminManager)

I used the same command on both clusters to create the topic aside from the connection details and in both cases I ran the command from inside the running broker container.

Locally

kafka-topics.sh --create --topic zevrant-video-stream --zookeeper localhost:2181 --partitions 1 --replication-factor 1 --config retention.ms=86400000

Kubernetes

kafka-topics.sh --create --topic zevrant-video-stream --zookeeper zevrant-kafka-zookeeper-service:443 --partitions 1 --replication-factor 1 --config retention.ms=86400000

I’m not really sure why this works in one place and not the other.

Attempting to connect a producer to the kubernetes broker i receive

Connection to node -1 (/<IP_ADDRESS>:30129) could not be established. Broker may not be available.

When querying zookeeper for broker information, zookeeper shows the broker as connected

zkCli.sh get /brokers/ids/1


{"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT"},"endpoints":("PLAINTEXT://<IP_ADDRESS>:9092"),"jmx_port":-1,"features":{},"host":"<IP_ADDRESS>","timestamp":"1622398259745","port":9092,"version":5}

What would cause the broker to connected, online, but unavailable?

statistics – How can two seemingly identical conditional expectations have different values?

Background

Suppose that we are using a simplified spherical model of the Earth’s surface with latitude $u in (-frac {pi} 2, frac {pi} 2)$ and longitude $v in (-pi, pi)$; then (if the radius is taken to be $1$), the surface area element is given by $mathrm{d}A = cos u mathrm{d}u mathrm{d}v$. Restricting attention to the hemisphere, $H$, where $u, v in (-frac {pi} 2, frac {pi} 2)$, a simple map projection from $H$ can be obtained by just taking the $x$ and $y$ coordinates via $x = cos u sin v$ and $y = sin u$, which is a smooth one-to-one transformation on $H$. Now, picking a point with coordinates $(U, V)$ on $H$ uniformly according to surface area, the joint density of $U$ and $V$ is $$f_{U, V}(u, v) = frac 1 {2pi} cos u, quad lvert u rvert, lvert v rvert < frac {pi} 2.$$

Question

$(a)quad$ Find $mathbb{E}(lvert sin U rvert mid V = 0)$.

$(b)quad$ Find $mathbb{E}(lvert Y rvert mid X = 0)$.

$(c)quad$ Observe that $lvert Y rvert = lvert sin U rvert$ and the event ${X = 0}$ is exactly the same as the event ${V = 0}$. How is it possible that $mathbb{E}(lvert Y rvert mid X = 0) neq mathbb{E}(lvert sin U rvert mid V = 0)$?

My working

I have omitted intermediate steps and only shown the essential parts.

$(a)$

$$begin{aligned}
because f_{U mid V = v}(u) & = frac 1 2 cos u,quad lvert u rvert, lvert v rvert < frac pi 2
\(5 mm) therefore mathbb{E}(lvert sin U rvert mid V = 0) & = int^{infty}_{-infty} lvert sin u rvert left(frac 1 2 cos uright) mathrm{d}u
\(5 mm) & = int^{frac pi 2}_0 sin u cos u mathrm{d}u
\(5 mm) & = frac 1 2
end{aligned}$$

$(b)$

$$begin{aligned}
\(5 mm) because f_{X, Y}(x, y) & = frac 1 {2 pi sqrt{1 – y^2 – x^2}}, quad x^2 + y^2 < 1
\(5 mm) therefore f_{Y mid X = x}(y) & = frac {frac 1 {2 pi sqrt{1 – y^2 – x^2}}} {int^{sqrt{1 – x^2}}_{-sqrt{1 – x^2}} frac 1 {2 pi sqrt{1 – y^2 – x^2}} mathrm{d}y}
\(5 mm) & = frac 1 {pi sqrt{1 – y^2 – x^2}}, quad x^2 + y^2 < 1
\(5 mm) implies mathbb{E}(lvert Y rvert mid X = 0) & = int^{infty}_{-infty} frac {lvert y rvert} {pi sqrt{1 – y^2}} mathrm{d}y
\(5 mm) & = frac 2 pi int^1_0 frac y {pi sqrt{1 – y^2}} mathrm{d}y
\(5 mm) & = frac 2 pi
end{aligned}$$


I think my answers to $(a)$ and $(b)$ are correct, but I am not sure how to approach $(c)$. Any intuitive explanations will be greatly appreciated! Also, if my answers to $(a)$ and/or $(b)$ are wrong, please do point out my mistakes 🙂

terminology – Are the definitions of loop in CS and in programming (standard/common) identical?

Looping in computer science and mathematics domain is generally associated with either some work to be done repeatedly or accumulated summation or accumulated product or summation or product in general, or any such arithmetic, logical or bitwise operations, it’s more of an abstract view of iteration than say in programming which is very specific and depends on the language and associated compiler with programming point of view it is also a convenient way of writing programs to have loops rather than call some functions multiple times which is not good practice, This should be clear enough.

How to compare two lists and return another list with values ​that are identical? – Flutter and Firebase

I have two lists returning IDs. I want to compare the two and return a new list with the IDs that appear in both. Then, save these values ​​in a new collection in Firebase.

What is the best way to do this? I found several similar topics but none helped.

I tried to use the intersection(), but it doesn’t return anything at the end. That’s how I’m getting the two lists:

List<Users> followingList;
List<Users> followersList;

  Future<List<Users>> _getFollowersUsers() async {
    Firestore db = Firestore.instance;

    QuerySnapshot querySnapshot = await db
        .collection('followers')
        .document(_userId)
        .collection("userFollowers")
        .getDocuments();

    List<Users> followersList = ();
    for (DocumentSnapshot item in querySnapshot.documents) {
      var data = item.data;
      if (data("id") == _userId) continue;

      Users user = Users();
      user.name = data("name");
      user.photoUrl = data("imageUrl");
      user.username = data("username");
      user.id = data("id");
      user.bio = data("bio");

      followersList.add(user);
    }

    return followersList;
  }

  Future<List<Users>> _getFollowingUsers() async {
    Firestore db = Firestore.instance;

    QuerySnapshot querySnapshot = await db
        .collection('following')
        .document(_userId)
        .collection("userFollowing")
        .getDocuments();

    List<Users> followingList = ();
    for (DocumentSnapshot item in querySnapshot.documents) {
      var data = item.data;
      if (data("id") == _userId) continue;

      Users user = Users();
      user.name = data("name");
      user.photoUrl = data("imageUrl");
      user.username = data("username");
      user.id = data("id");
      user.bio = data("bio");

      followingList.add(user);
    }

    return followingList;
  }

  getFinalList() {
    var finalList =
        followingList.toSet().intersection(followersList.toSet()).toList();

    print(finalList);
  }

sharepoint online – .aspx file uploaded to document library won’t open, despite identical file uploaded earlier working fine

I uploaded an .aspx file (a simple HTML button with a mailto: link) to a document library on my SharePoint Online site, with the intention of putting it into an Embed web part on a separate page. This worked fine: The page now has an Embed web part that contains the button.

Now, I want to make changes to the .aspx file. I uploaded a new version of the file to the same library. However, rather than working as expected, the new version has different behavior:

  • If I click on the newly uploaded .aspx file from the library, it downloads instead of rendering in my browser.
  • If I use the newly uploaded .aspx file as a target for my Embed web part, the button does not appear.
  • If I manually navigate to the URL of the newly uploaded .aspx file, I receive the following error message:

Sorry, something went wrong

File Not Found.

Debug Only Section Begins (visible in DEBUG builds or prodbubble)——————
System.IO.FileNotFoundException: File Not Found.
at Microsoft.SharePoint.ApplicationRuntime.SPVirtualFile.CalculateFileDependencies(HttpContext context, SPRequestModuleData basicRequestData, ICollection& directDependencies, ICollection& childDependencies)
at Microsoft.SharePoint.ApplicationRuntime.SPDatabaseFile.EnsureDependencies(HttpContext context, SPRequestModuleData requestData)
at Microsoft.SharePoint.ApplicationRuntime.SPDatabaseFile.EnsureCacheKeyAndViewStateHash(HttpContext context, SPRequestModuleData requestData)
at Microsoft.SharePoint.ApplicationRuntime.SPDatabaseFile.GetVirtualPathProviderCacheKey(HttpContext context, SPRequestModuleData requestData)
at Microsoft.SharePoint.ApplicationRuntime.SPVirtualPathProvider.GetCacheKey(String virtualPath)
at System.Web.Compilation.BuildManager.GetCacheKeyFromVirtualPath(VirtualPath virtualPath, Boolean& keyFromVPP)
at System.Web.Compilation.BuildManager.GetVPathBuildResultFromCacheInternal(VirtualPath virtualPath, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp)
at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
Debug Only Section Ends——————

TECHNICAL DETAILS

Troubleshoot issues with Microsoft SharePoint Foundation.
Correlation ID: 5835c19f-d083-0000-d1f2-3eb51cd2d202

Date and Time: 4/23/2021 4:55:14 PM

I initially thought there must be something wrong with the new file I had uploaded, so I tried uploading an exact copy of the original file. No luck, same broken behavior, despite the files being exactly the same.

The original file still works, but I am hesitant to make any changes to it now, in case doing so will cause it to display this broken behavior as well.

How can I get a newly uploaded file to behave like the ones I uploaded before (open instead of downloading when clicked on, valid target for an Embed web part)?

How to unlink two identical local drives Windows 10?

So I recently switched out my HDD for an SSD drive by first cloning the Local Disk (C:) onto the SSD which I gave the name “SSD (S:).” I then booted my pc from the SSD and everything went smoothly. Except that when I went into Quick Access I had 3 drives! I decided to unplug my HDD to try to find out what’s the problem, and then Quick Access said I had 2 drives still. One was named Local Disk (C:) which was actually my SSD drive, and the other had a question mark over it and was titled “S:” What the heck! So now my original SSD is named Local Disk (C:) and I have an extraneous drive named “S:”?

So here’s what I did to try and get rid of the question mark over the “S:” drive.

I did research and decided to go into cmd (command prompt) and type this code

subst S: C:

After doing this, the question mark disappeared and the drive became “Local Drive (S:)” and was an identical copy of Local Drive (C:).

So heres the issue-

I succesfully have switched out my HDD drive for the SSD and things work a lot faster. However, I fear that some file directory’s are going to get messed up because now those two Local Disk drives that are identical are also somehow linked, and adding or deleting something from one drive does the same in the other drive. Also, going into task manager or optimize drivers settings, my computer only reads one drive- Local Disk (C:).

So this is what it means- I somehow have an identical cloned Local Disk drive that doesn’t actually exist, and is somehow linked to my other drive.

What I want to do is delete that extraneous drive-Local Disk (S:) so that my files do not get corrupted.

Here is a picture of my Disk Management:
enter image description here

Sorry if this was confusing, but I am lost. Anything will help!

command line – Almost identical batch files, one works, the other doesn’t (in Windows)

I am running this in a batch file and it works perfectly:

rem    Make this command window miminize itself...
if not DEFINED IS_MINIMIZED set IS_MINIMIZED=1 && start "" /min "%~dpnx0" %* && exit

cd /d %~dp0

cls
@echo off
rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    This will attempt to download the subtitle file from a YouTube video or channel, from a copied clipboard link.
rem    
rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@echo off
title Download Subtitles (From Clipboard Link)
color 0f

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Check that youtube-dl is up to date...
start /wait /min youtube-dl.exe -U

rem    Cleanup from last time if it was updated while the process was running...
if exist "youtube-dl.exe.new" del "youtube-dl.exe" & ren "youtube-dl.exe.new" "youtube-dl.exe"

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Create "NEWSubtitles" folder.
if not exist "..NEWSubtitles" md "..NEWSubtitles"

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Paste url into clipboard.txt...
set clipboard_link=%RANDOM%%RANDOM%
winclip.exe -p %clipboard_link%.txt

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Download subtitles to randomly named folder using youtube-dl (using clipboard.txt).
rem    Setting a "%RANDOM%" folder here allows multiple downloads to take place at the same time...
set download_temp=%RANDOM%%RANDOM%
md %download_temp%
start /wait /min youtube-dl.exe --ignore-errors --write-auto-sub --sub-format ttml --skip-download -o "%download_temp%%%(upload_date)s - %%(uploader)s - %%(title)s.%%(ext)s" -a %clipboard_link%.txt

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Delete the now useless clipboard.txt file...
del %clipboard_link%.txt

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Remove non-standard characters from file names in the "%download_temp%" folder.
xcopy "SpecialChar*.bat" "%download_temp%" /i /r /v /k /f /c /h /y >nul 2>&1
cd /d %download_temp%
call rename.bat
cd /d ..
del "%download_temp%*.bat"

rem    ----------------------------------------------------------------------------------------------------------
rem    Clean up the downloaded subtitle files with powershell.
xcopy "ReplaceTextCleanup_Subtitles.txt" "%download_temp%"  /i /r /v /k /f /c /h /y >nul 2>&1
cd /d %download_temp%
ren "Cleanup_Subtitles.txt" "Cleanup_Subtitles.cmd"
call "Cleanup_Subtitles.cmd"
del "Cleanup_Subtitles.cmd"
cd /d ..

rem    ----------------------------------------------------------------------------------------------------------
rem    Move the subtitle files to "NEWSubtitles"
move /y "%download_temp%*" "..NEWSubtitles"
rd /s /q "%download_temp%"

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
exit

It calls one other batch file “Cleanup_Subtitles.cmd” that contains this:

@echo off

rem    Rename ttml files to txt.
if exist *.ttml FOR /F "tokens=*" %%G IN ('dir /b *.ttml') DO ren "%%G" "%%~nG.txt"

rem    Clean up unwanted text in all .txt files.
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '<?xml version=""""1.0"""" encoding=""""utf-8"""" ?>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '<tt xml:lang="""en""" xmlns="""http://www.w3.org/ns/ttml""" xmlns:ttm="""http://www.w3.org/ns/ttml#metadata""" xmlns:tts="""http://www.w3.org/ns/ttml#styling""" xmlns:ttp="""http://www.w3.org/ns/ttml#parameter""" ttp:profile="""http://www.w3.org/TR/profile/sdp-us""" >', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '<head>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '<styling>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '<style xml:id="""s1""" tts:textAlign="""center""" tts:extent="""90%% 90%%""" tts:origin="""5%% 5%%""" tts:displayAlign="""after"""/>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '<style xml:id="""s2""" tts:fontSize=""".72c""" tts:backgroundColor="""black""" tts:color="""white"""/>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '</styling>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '<layout>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '<region xml:id="""r1""" style="""s1"""/>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '</layout>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '</head>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '<body region="""r1""">', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '<div>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '<p begin=""""', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '""" end="""', ' to ' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '"""" style=""""s2"""">', ' ---> ' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '</p>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '&#39;', '''' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '</div>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '</body>', '' | Set-Content $_.FullName}"
start /wait /min Powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem '*.txt' | ForEach-Object {(Get-Content $_) -replace '</tt>', '' | Set-Content $_.FullName}"

goto eof

All of that does exactly what it should, takes a copied link to a YouTube channel, downloads the subtitle files for each video to a %download_temp% folder, copies the cleanup file to that same folder, renames it to cmd, calls it, then everything returns to the parent batch file that in turn, moves the subtitle files to the last destination shown in the first bunch of commands shown above: “..NEWSubtitles”.

Now if I call that exact same file “Cleanup_Subtitles.cmd” from the following batch file that does an almost identical thing (it just asks for a date to be typed in around the beginning of it) it does not work.
What happens is, the subtitle files are copied to the NEW folder just like they should be, but they end up not getting processed by the “Cleanup_Subtitles.cmd” file, although I can see that it does run that file because the minimized powershell windows are blinking in my tray, just a lot faster, like it’s not processing anything.
In this case when the subtitle files end up in the NEW folder and I open one, powershell has done nothing to them, they still contain all the xml code, that does get removed when using the first batch file I posted above.

Here’s the non-working one, that has exactly the same lines at the end of it as the first one I posted and calls the exact same “Cleanup_Subtitles.cmd” file…

cd /d %~dp0

cls
@echo off
rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    After typing the date in, this will download the subtitles from all videos from a YouTube
rem    channel after the provided date, using the channel url copied to the clipboard.
rem    
rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@echo off
title Download Subtitles After Date
color 0f

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
cls
rem    Define a variable containing a single space character
for /f %%A in ('"prompt $H &echo on &for %%B in (1) do rem"') do set GAP=%%A

rem    Set the input date as variables %year%%month%%day%
echo.
echo.
echo    ---------------------------------------------------------------------------------
echo    Please make sure you have copied a YouTube channel web address to your clipboard.
echo.
echo    Only subtitles from AFTER the date you enter will be downloaded.
echo.
echo    You must type the day and month as 2 digit numbers, for example April would be 04
echo    ---------------------------------------------------------------------------------
echo.
set /p day="%GAP%   Please type the DAY: "
echo.
set /p month="%GAP%   Please type the MONTH: "
echo.
set /p year="%GAP%   Please type the YEAR: "
echo.
echo    Please wait...

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Check that youtube-dl is up to date...
start /wait /min youtube-dl.exe -U

rem    Cleanup from last time if it was updated while the process was running...
if exist "youtube-dl.exe.new" del "youtube-dl.exe" & ren "youtube-dl.exe.new" "youtube-dl.exe"

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Create "NEWSubtitles" folder.
if not exist "..NEWSubtitles" md "..NEWSubtitles"

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Paste url into clipboard.txt...
set clipboard_link=%RANDOM%%RANDOM%
winclip.exe -p %clipboard_link%.txt

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Download subtitles to randomly named folder using youtube-dl (using clipboard.txt).
rem    Setting a "%RANDOM%" folder here allows multiple downloads to take place at the same time...
set download_temp=%RANDOM%%RANDOM%
md %download_temp%
start /wait /min youtube-dl.exe --ignore-errors --dateafter %year%%month%%day% --write-auto-sub --sub-format ttml --skip-download -o "..NEWSubtitles%%(upload_date)s - %%(uploader)s - %%(title)s.%%(ext)s" -a %clipboard_link%.txt

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Delete the now useless clipboard.txt file...
del %clipboard_link%.txt

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Remove non-standard characters from file names in the "%download_temp%" folder.
xcopy "SpecialChar*.bat" "%download_temp%" /i /r /v /k /f /c /h /y >nul 2>&1
cd /d %download_temp%
call rename.bat
cd /d ..
del "%download_temp%*.bat"

rem    ----------------------------------------------------------------------------------------------------------
rem    Clean up the downloaded subtitle files with powershell.
xcopy "ReplaceTextCleanup_Subtitles.txt" "%download_temp%"  /i /r /v /k /f /c /h /y >nul 2>&1
cd /d %download_temp%
ren "Cleanup_Subtitles.txt" "Cleanup_Subtitles.cmd"
call "Cleanup_Subtitles.cmd"
del "Cleanup_Subtitles.cmd"
cd /d ..

rem    ----------------------------------------------------------------------------------------------------------
rem    Move the subtitle files to "NEWSubtitles"
move /y "%download_temp%*" "..NEWSubtitles"
rd /s /q "%download_temp%"

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
exit

Hint: It’s not the %GAP% causing it, already took that out and nothing changed.

This is baffling me because each of the large (parent) batch files both have the exact same commands at the end, this:

rem ^^^^^^^^^^^^^^^^^^^^ REST OF BATCH FILE ^^^^^^^^^^^^^^^^^^^^
rem vvvvvvvvvvvvvvvvv END OF BOTH BATCH FILES  vvvvvvvvvvvvvvvvv
rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
rem    Remove non-standard characters from file names in the "%download_temp%" folder.
xcopy "SpecialChar*.bat" "%download_temp%" /i /r /v /k /f /c /h /y >nul 2>&1
cd /d %download_temp%
call rename.bat
cd /d ..
del "%download_temp%*.bat"

rem    ----------------------------------------------------------------------------------------------------------
rem    Clean up the downloaded subtitle files with powershell.
xcopy "ReplaceTextCleanup_Subtitles.txt" "%download_temp%"  /i /r /v /k /f /c /h /y >nul 2>&1
cd /d %download_temp%
ren "Cleanup_Subtitles.txt" "Cleanup_Subtitles.cmd"
call "Cleanup_Subtitles.cmd"
del "Cleanup_Subtitles.cmd"
cd /d ..

rem    ----------------------------------------------------------------------------------------------------------
rem    Move the subtitle files to "NEWSubtitles"
move /y "%download_temp%*" "..NEWSubtitles"
rd /s /q "%download_temp%"

rem    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
exit

One works, the next doesn’t. This is driving me crazy!

Why does the first one work but the next one doesn’t and what needs changing in the second one so it works, hopefully without breaking the first one?

Cheers guys and sorry that this is such a huge post, but I wanted to include every last detail and I think the solution isn’t going to be complicated, I just have no clue why one would work and the other wouldn’t when both the main batch files are doing almost the exact same thing as each other.

Here’s both files shown in ExamDiff so you can see the differences:

enter image description here