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

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

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

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

905閲覧

anacondaのjupyter notebook上でpythonを使用し、IEと指定のテキストファイルを起動したいです。

mahr

総合スコア10

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/08/01 12:49

前提・実現したいこと

anacondaのjupyter notebook上で下記pythonのコードを記載し、以下を実行しようとしています。
エラーが出て上手くいかないのですが、原因がわかり方いらっしゃいましたら教えて頂けますと幸いです。

【実現したいこと】
①IEを起動する
②IEを閉じると、テキストファイルを開く
※開くテキストファイルは、Dドライブ直下のtest.txtというファイルです。

発生している問題・エラーメッセージ

OSError Traceback (most recent call last) <ipython-input-1-50b3628cf635> in <module> 3 notepad = r"D:\test.txt" 4 subprocess.run(ie) ----> 5 subprocess.run(notepad) 6 ~\anaconda3\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs) 491 kwargs['stderr'] = PIPE 492 --> 493 with Popen(*popenargs, **kwargs) as process: 494 try: 495 stdout, stderr = process.communicate(input, timeout=timeout) ~\anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text) 856 encoding=encoding, errors=errors) 857 --> 858 self._execute_child(args, executable, preexec_fn, close_fds, 859 pass_fds, cwd, env, 860 startupinfo, creationflags, shell, ~\anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session) 1309 # Start the process 1310 try: -> 1311 hp, ht, pid, tid = _winapi.CreateProcess(executable, args, 1312 # no special security 1313 None, None, OSError: [WinError 193] %1 は有効な Win32 アプリケーションではありません。

該当のソースコード

import subprocess
ie=r"C:\Program Files\Internet Explorer\iexplore.exe"
notepad = r"D:\test.txt"
subprocess.run(ie)
subprocess.run(notepad)

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

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

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

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

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

guest

回答1

0

ベストアンサー

こうです。

python

1import subprocess 2ie=r"C:\Program Files\Internet Explorer\iexplore.exe" 3notepad = r"C:\Windows\notepad.exe D:\test.txt" 4popen = subprocess.Popen(ie, shell=True ) 5popen.wait() 6subprocess.run(notepad, shell=True)

投稿2021/08/01 13:15

ppaul

総合スコア24666

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

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

mahr

2021/08/01 13:30 編集

ありがとうございます! なぜ、 r"D:\test.txt"ではなくr"C:\Windows\notepad.exe D:\test.txt"なのでしょうか。 メモ帳本体のファイルパスと開きたいファイルのファイルパスの両方を入力する必要があるということでしょうか?
ppaul

2021/08/01 15:48

関連づけができていればnotepad = r"D:\test.txt"でも動くはずですが、エラーが出ているので念のためnotopadも指定しました。
mahr

2021/08/02 11:55

かしこまりました。 ご親切にありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問