質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

Q&A

0回答

876閲覧

フォームから送られてきた圧縮pdeファイルを解凍してpdeファイルを実効したい

mote

総合スコア128

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

0グッド

0クリップ

投稿2018/10/15 08:40

Node.jsのモジュールであるchild_procssを用いて、OSコマンドを打てるようにしました。
htmlから送られてきたファイルを、解凍、コピー、ls並び替えは出来たのですが、
解凍したファイルをchild_processで実行させたいです。
pdeファイルの"hello world"がサーバーコンソール内に出てくれればいいのですが、
やり方がわからないです。。。

js

1var app = require("http").createServer(handler), 2io = require("socket.io").listen(app), 3fs = require("fs") ; 4const file = require("./file.js"); 5 6app.listen(3000) ; 7console.log("server start!"); 8function handler(req,res){ 9 fs.readFile(__dirname+"/file.html",function(err,data){ 10 if (req.url == '/fileupload') { 11 file(req,res); 12 res.write('File uploaded and moved!'); 13 res.end(); 14 }else{ 15 res.writeHead(200); 16 res.write(data); 17 res.end(); 18 } 19 }); 20} 21io.sockets.on("connection",function(socket){ 22 console.log("connect") ; 23 socket.on("upload",function(data){ 24 console.log(data) ; 25 socket.emit("move",data); 26 }); 27}); 28

html

1<!DOCTYPE html> 2<html lang="ja" > 3 <head> 4 <meta charset="utf-8"> 5 <title>file,pass</title> 6 </head> 7 <body> 8 <form action="fileupload" method="post" enctype="multipart/form-data"> 9 <input type="file" name="filetoupload"><br> 10 <input type="submit"> 11 </form> 12 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> 13 </script> 14 <script src="http://localhost:3000/socket.io/socket.io.js"></script> 15 16 17<script> 18function act(){ 19 var socket = io.connect(); 20 $("#uploadfile").submit(function(e){ 21 socket.emit("emit_data",e); 22 e.preventDefault();//submitの実行を止める 23 }); 24 socket.on("data_from_server",function(data){ 25 console.log(data); 26 }); 27}; 28act(); 29</script> 30 </body> 31</html> 32

js

1var fs = require("fs"); 2var formidable = require("formidable") ; 3const child = require("./childprocess.js"); 4const process = require("./process.js") 5module.exports=function file(req,res){ 6 var form = new formidable.IncomingForm(); 7 form.parse(req, function (err, fields, files) { 8 var oldpath=files.filetoupload.path ; 9 var newpath="./File_data/"+files.filetoupload.name ; 10 fs.rename(oldpath,newpath,function(err){ 11 if(err) res.end(err) ; 12 child.zip(newpath); 13 child.ls(); 14 child.copy(); 15 console.log("file,move",newpath); 16 }); 17 }); 18 } 19

js

1const {spawn} = require('child_process') ; 2const file = require("./file.js") ; 3var fs =require("fs"); 4 5module.exports = class child{ 6 constructor(newpath){ 7 var newpath = newpath ; 8 } 9 //zip解凍 10 static zip(newpath){ 11 var zip = spawn("unzip",[newpath,"-d","./File_data"]); 12 zip.on("exit",function(code,signal){ 13 console.log("file thawing!"); 14 }); 15 } 16 //並び替え 17 static ls(){ 18 var ls = spawn("ls",["-lh","./File_data"]); 19 ls.stdout.on('data', function(data){ 20 console.log(`stdout: ${data}`); 21 }); 22 } 23 //ディレクトリコピー 24 static copy(){ 25 var copy = spawn("cp",["-r","./File_data","./File_data_copy"]); 26 copy.on("exit",function(code,signal){ 27 console.log("fd copied!"); 28 }); 29 } 30 31 } 32

pde

1print("Hello World!");

↑このファイルを圧縮してhtmlからsocket.ioでサーバーに送り、"formidable"でサーバー内で扱えるようにしました。
zipファイルの所得と解凍は出来ているので、後はこのファイルをchild_processで実効できるようにしたいです!

どなかNode.jsに詳しい方よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問