Comments (6)
Hi @Saadnajmi , can you tell me something about it?
from react-native-macos.
This sort of issue comes up in our repo a lot. Here's why it's currently not possible:
exec
, child_process
, along with many other Javascript packages are node modules, but not react native style native modules. They are re different ways to execute native code from Javascript that are currently incompatible.
Node modules are with the Node-API, while React Native modules are written with either the legacy native module system, or as turbo modules, the latter of which uses a layer called JSI to talk to native code.
This issue is with React Native in general (you wouldn't be able to run your above code on iOS or Android), but it is more pronounced on our desktop platform, where one expects all their favorite node APIs to work.
There is a project from @vmoroz (feel free to correct my mistakes describing) to refactor the JSI layer mentioned to support the node-api, allowing node modules to work with react native turbo modules. Then, your request would be something that is possible. Unfortunately, I don't have an ETA for when that project will land, or whether it would get adopted by React Native or React Native macOS. It's currently getting prototyped on React Native windows.
from react-native-macos.
@ospfranco: Do shell commands work on sol?
It seems to me that you have done something with JSI, do you think it is possible?
@Saadnajmi : How come this command works /sbin/ping
:
import {spawn, kill} from 'react-native-childprocess'
useEffect(() => {
const fetchData = async () => {
cmdID = await spawn('/sbin/ping', ['google.com'], {
pwd: "/",
stdout: (output) => {
console.log('>>>', output)
}
});
console.log(cmdID)
}
fetchData()
.catch(console.error);
}, [])
However, any different command does not work.
Like ls
or pwd
don't work.
Maybe a set of commands found in /sbin
work.
from react-native-macos.
Simple native implementation and binding
Probably won't work with Sandboxing enabled though. So no, React Native probably shouldn't/can't implement this, also huge security vunerability for bad actors.
from react-native-macos.
@ospfranco: Do shell commands work on sol?
It seems to me that you have done something with JSI, do you think it is possible?
@Saadnajmi : How come this command works
/sbin/ping
:import {spawn, kill} from 'react-native-childprocess' useEffect(() => { const fetchData = async () => { cmdID = await spawn('/sbin/ping', ['google.com'], { pwd: "/", stdout: (output) => { console.log('>>>', output) } }); console.log(cmdID) } fetchData() .catch(console.error); }, [])However, any different command does not work.
Like
ls
orpwd
don't work.Maybe a set of commands found in
/sbin
work.
react-native-childprocess seems to be a rewrite of child_process as a react native module is why it works
from react-native-macos.
@okwasniewski , @Saadnajmi , @ospfranco : I don't know but it seems like maybe it works like this:
import { spawn, kill } from 'react-native-childprocess';
....
const [pwd, setPwd] = useState(undefined);
useEffect(() => {
let cmdID;
const shell = async () => {
cmdID = await spawn('/bin/sh', ['-c','ls'], {
pwd: '/Users/',
stdout: (output) => {
const paths = output.split('\n').filter(Boolean).filter(val => val !== "Shared");
if(paths.length === 1) setPwd(`/Users/${paths[0]}/Desktop`)
},
stderr: (output) => console.log('stderr:', output),
terminate: (output) => console.log('terminate:', output),
});
};
shell().catch(console.error);
return () => {
kill(cmdID);
};
}, []);
useEffect(() => {
if(pwd === undefined) return
let cmdID;
const shell = async () => {
cmdID = await spawn('/bin/sh', ['-c','ls'], {
pwd,
stdout: (output) => {
console.log(output.split('\n').filter(Boolean))
},
stderr: (output) => console.log('stderr:', output),
terminate: (output) => console.log('terminate:', output),
});
};
shell().catch(console.error);
return () => {
kill(cmdID);
};
}, [pwd]);
Let me know what you think.
from react-native-macos.
Related Issues (20)
- [SocketRocket] Upstream visionOS Support
- Is __apply_Xcode_12_5_M1_post_install_workaround now obsolete? HOT 4
- The transform style does not work in version 0.73.* HOT 7
- Unable to resolve module
- Input focus area doesn't move when parent view is transformed HOT 7
- [Fabric] TextInput UI is not updated when changing prop `value` or calling `inputRef.current.clear()` / `inputRef.current.setNativeProps({text: ''})` HOT 2
- Web inspector flashing on production/release build when starting the app HOT 6
- Keyboard shortcuts (copy, paste, select) not working in TextInput HOT 6
- "Fatal error: 'ExpoModulesCore/ExpoModulesCore.h' file not found" in run-macos HOT 3
- I want to request a feature like in-app Purchases support, and Firebase support. HOT 3
- useWindowDimensions causes infinite re-rendering HOT 3
- Wrong image pixel density version on initial launch HOT 6
- Right click context menu HOT 5
- No version of react-native-macos@^0.70.0-0 found! HOT 1
- <Text onBlur={() => {}}> throws -[RCTTextView setOnBlur:]: unrecognized selector sent HOT 1
- How can i get the microphone or camera permission in react-native-macOS, i am using react-native-permissions HOT 3
- ERROR: No bundle URL present. HOT 10
- `Text` elements' `backgroundColor` style prop extends to the entire background
- NSTabView doesn't send mouseUp event because it doesn't inherit from NSControl HOT 7
- How can I make the react-native-macos work with ios? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-macos.