Skip to content

Unable to execute py script using exec command in nextjs #61750

@krishnaacharyaa

Description

@krishnaacharyaa

Link to the code that reproduces this issue

https://github.com/krishnaacharyaa/python-nextjs

To Reproduce

Just clone the repo
Breif is:
I am trying to run simple py/sh scripts from nextjs using exec but i am not able to achieve it.

Kind help would be much appreciated.

Process is simple:

I am calling server Actions in my code, which executes the script

page.tsx

"use client";

import { pythonExec } from "./action";

export default function PythonClicker() {
  return <div onClick={() => pythonExec()}>Hello there</div>;
}

server action

"use server";

// import { exec } from "child_process";
export const pythonExec = async () => {
  const { exec } = require("child_process");
  console.log("I am called  ");
  exec('"sample-script.py"');
};

sample-script.py

print("Hello world")

p.s: I am called is being logged, only the "Hello world" is not getting logged.
I also want to return values from the script and use consume it in my server action

Reproducible code: https://github.com/krishnaacharyaa/python-nextjs

Current vs. Expected behavior

Along with log of "I am called in ", I expect to see the "Hello world" message aswell

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:34 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8103
Binaries:
  Node: 21.0.0
  npm: 10.2.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.1.0
  eslint-config-next: 14.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Data fetching (gS(S)P, getInitialProps), Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link), Script optimization (next/script)

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Linking and NavigatingRelated to Next.js linking (e.g., <Link>) and navigation.Pages RouterRelated to Pages Router.RuntimeRelated to Node.js or Edge Runtime with Next.js.bugIssue was opened via the bug report template.staleThe issue has not seen recent activity.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions